PHP Common validation Regular expression, PHP regular expression
Number, mobile phone number, QQ number, URL address legality check
1. Verify that it is an integer
1 function isnumber ($val)2 {3 if(ereg $val))4 returntrue; 5 return false ; 6 }
2. Verify that the phone number is
1 function isphone ($val) {2 3 if (ereg("^1[ 1-9][0-9]{9}$ ",$val))4 returntrue; 5 return false ; 6 7 8 }
3. Verify that the QQ number is valid
1 function isqq ($val) {2 3 if ( Ereg("^[1-9][0-9]{4,12}$",$val))4 returntrue ; 5 return false ; 6 7 8 }
4. Verify that the URL address is legitimate
1 functionIsurl ($s) { 2 return Preg_match('/^http[s]?:\ /\/'.3' (([0-9]{1,3}\.) {3} [0-9] {1,3} './/URL-199.194.52.184 in IP form4'|'.//Allow IP and domain (domain name)5' ([0-9a-z_!~*\ ' ()-]+\.) *'.//domain name-www. 6' ([0-9a-z][0-9a-z-]{0,61})? [0-9a-z]\.]//level two domain name7' [a-z]{2,6}] './/First level domain-. com or. Museum8' (: [0-9]{1,4})? './/Port-:9'((\/\?)|'.//a slash isn ' t required if there is no file nameTen' (\/[0-9a-za-z_!~\ ' \ (\) \[\]\.;\?:@&=\+\$,%#-\/^\*\|] *)?) $/', One $s) = = 1; A}
It is easy to use, such as verifying that the phone number is valid:
$val= ' 15093691582 '; Isphone ($val);
http://www.bkjia.com/PHPjc/1048725.html www.bkjia.com true http://www.bkjia.com/PHPjc/1048725.html techarticle PHP Common validation Regular expression, PHP regular expression number, mobile phone number, QQ number, URL address legality check 1. Verify that the integer 1 function isnumber ($val) 2 {3 if (Ereg ("^[0-...