Use C++regex to determine the format of numbers, real numbers, IP, e-mails, words, phone numbers, dates, etc.
#include "check.h" #include <regex> #include <string>using namespace std;
The judgment is all digital bool All_digit (const string &s) { regex R ("^[0-9]*$");
Determine the word bool All_alpha (const string &s) { regex R ("^[[:alpha:]]*$"); Return Regex_match (S,R);}
The judgment is all word or number bool All_alnum (const string &s) { regex R ("^[[:alnum:]]*$"); Return Regex_match (S,R);}
Judge the integer bool Is_int (const string &s) { regex R ("^[-]?" ( 0| ([1-9][0-9]*)) $"); Return Regex_match (S,R);}
Judge the real number bool Is_float (const string &s) { regex R ("^-") ( 0| ([1-9][0-9]*)) \\. [0-9]+$ "); Return Regex_match (S,R);}
Judge Ipbool is_ip (const string &s) { regex R ("^ (((25[0-5]) | ( 2[0-4][0-9]) | (1[0-9]{2}) | (([1-9][0-9]?) | 0)) \ \.) {3} "
"((25[0-5)) | (2[0-4][0-9]) | (1[0-9]{2}) | (([1-9][0-9]?) | 0))) ($ "); Return Regex_match (S,R);}
Determine the phone number, starting with 0 or 1, and 11-bit numbers make up bool Is_phone (const string &s) { regex R ("^[01][0-9]{10}$"); Return Regex_match (S,R);}
Judgment date 1900-2,999 years between bool Is_date (const string &s) { regex R ("^[12][0-9]{3}-(0[1-9]) | ( 1[0-2])-((0[1-9)) | ( [12] [0-9]) | (3[01])) $"); Return Regex_match (S,R);}
Determine the e-mail address bool Is_mail (const string &s) { regex R ("^[[:alnum:]][email protected][[:alnum:]]+\\.[ a-z]+$ "); Return Regex_match (S,R);}
C + + Regex