直接看代碼:
//正則驗證手機號 正確返回 truefunction preg_mobile($mobile) {if(preg_match("/^1[34578]/d{9}$/", $mobile)) {return TRUE;} else {return FALSE;}}//驗證電話號碼function preg_tel($tel) {if(preg_match("/^(/(/d{3,4}/)|/d{3,4}-)?/d{7,8}$/", $tel)) {return TRUE;} else {return FALSE;}}//驗證身份證號(15位或18位數字)function preg_idcard($idcard) {if(preg_match("/^/d{15}|/d{18}$/", $idcard)) {return TRUE;} else {return FALSE;}}//驗證是否是數字(這里小數點會認為是字符)function preg_digit($digit) {if(preg_match("/^/d*$/", $digit)) {return TRUE;} else {return FALSE;}}//驗證是否是數字(可帶小數點的數字)function preg_num($num) {if(is_numeric($num)) {return TRUE;} else {return FALSE;}}//驗證由數字、26個英文字母或者下劃線組成的字符串function preg_str($str) {if(preg_match("/^/w+$/", $str)) {return TRUE;} else {return FALSE;}}//驗證用戶密碼(以字母開頭,長度在6-18之間,只能包含字符、數字和下劃線)function preg_password($str) {if(preg_match("/^[a-zA-Z]/w{5,17}$/", $str)) {return TRUE;} else {return FALSE;}}//驗證漢字function preg_chinese($str) {if(preg_match("/^[/u4e00-/u9fa5],{0,}$/", $str)) {return TRUE;} else {return FALSE;}}//驗證Email地址function preg_email($email) {if(preg_match("/^/w+[-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/", $email)) {return TRUE;} else {return FALSE;}}//驗證網址URLfunction preg_link($url) {if(preg_match("/http:////[/w.]+[/w//]*[/w.]*/??[/w=&/+/%]*/is", $url)) {return TRUE;} else {return FALSE;}}//騰訊QQ號function preg_qq($qq) {if(preg_match("/^[1-9][0-9]{4,}$/", $qq)) {return TRUE;} else {return FALSE;}}//驗證中國郵政編碼 6位數字function preg_post($post) {if(preg_match("/^[1-9]/d{5}(?!/d)$/", $post)) {return TRUE;} else {return FALSE;}}//驗證IP地址function preg_ip($ip) {if(preg_match("/^[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3}$/", $ip)) {return TRUE;} else {return FALSE;}}以上就是PHP正則驗證手機號、身份證、數字ip等的全部內容,希望對大家的學習和解決疑問有所幫助,也希望大家多多支持武林網。
|
新聞熱點
疑難解答