首页 > 开发 > Php > 正文

PHP正则验证手机号、身份证、数字ip等

2020-07-03 12:54:47
字体:
来源:转载
供稿:网友
这篇文章主要为大家详细介绍了PHP正则验证手机号、身份证、数字ip等,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴。

直接看代码:

//正则验证手机号 正确返回 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等的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持错新网。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表