Skip to content

Instantly share code, notes, and snippets.

@iamazeem
Last active May 22, 2019 07:23
Show Gist options
  • Save iamazeem/7924068fe8564f8a22277fe48aa31496 to your computer and use it in GitHub Desktop.
Save iamazeem/7924068fe8564f8a22277fe48aa31496 to your computer and use it in GitHub Desktop.
// Validate date using regex
// Format: YYYY/MM/DD
#include <iostream>
#include <regex>
bool isDateValid( const std::string& date )
{
std::regex regexDate { R"(\d{4}/\d{2}/\d{2})" };
std::smatch match;
std::regex_match( date, match, regexDate );
std::cout << match.str() << std::endl;
return !match.str().empty();
}
int main()
{
const std::string date { "2016/12/17" };
std::cout << std::boolalpha << isDateValid( date ) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment