PHP commonly used to verify the validity of regular expression numbers, mobile phone numbers, QQ numbers, and URLs 1. verify that it is an integer of 1 functionisNumber ($ val) 2 {3if (ereg (^ [0-9] + $, $ val) 4 returntrue; 5 returnfalse; 6 PHP regular expression
Validity verification of numbers, mobile phone numbers, QQ numbers, and Url addresses
1. verify whether it is an integer
1 function isNumber($val)2 {3 if(ereg("^[0-9]+$", $val))4 return true;5 return false;6 }
2. verify whether the mobile phone number is used
1 function isPhone($val){2 3 if (ereg("^1[1-9][0-9]{9}$",$val))4 return true;5 return false;6 7 8 }
3. verify if it is a valid QQ number
1 function isQQ($val){2 3 if (ereg("^[1-9][0-9]{4,12}$",$val))4 return true;5 return false;6 7 8 }
4. verify whether the Url address is valid
1 function isUrl ($ s) {2 return preg_match ('/^ http [s]? :\/\/'. 3' ([0-9] {1, 3 }\.) {3} [0-9] {1, 3 }'. // URL in IP format-199.194.52.184 4 '| '. // allow IP address and DOMAIN (DOMAIN name) 5' ([0-9a-z _! ~ * \ '()-] + \.) *'. // Domain name-www. 6' ([0-9a-z] [0-9a-z-] {0, 61 })? [0-9a-z] \. '. // second-level domain 7' [a-z] {2, 6 })'. // first level domain -. com or. museum 8' (: [0-9] {1, 4 })? '. // Port-: 80 9 '((\/\?) | '. // A slash isn' t required if there is no file name 10' (\/[0-9a-zA-Z _!~ \ '\ (\) \ [\] \.; \? : @ & =\+ \ $, % #-\/^ \ * \ |] *)? $/', 11 $ s) = 1; 12}
The usage is simple, such as verifying whether the mobile phone number is valid:
$val='15093691582';isPhone($val);