php 数字号码,PHP正则验证手机号、身_份_证号码、数字ip

//正则验证手机号 正确返回 true

function 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;

}

}

//验证网址URL

function 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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值