php正则验证邮箱、手机号、姓名、身份证、特殊符号等

                                                  php正则验证邮箱、手机号、姓名、身份证、特殊符号等

一、转载地址:https://www.cnblogs.com/dreamysky/p/5920247.html

二、转载内容

1、邮箱

$email='1515212@qq';
$preg_email='/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@([a-zA-Z0-9]+[-.])+([a-z]{2,5})$/ims';
if(preg_match($preg_email,$email)){
    echo 1;
}else{
    echo 0;
}

2、手机号

$phone='13651121610';
$preg_phone='/^1[34578]\d{9}$/ims';
if(preg_match($preg_phone,$phone)){
    echo 1;
}else{
    echo 0;
}

3、固定号码

$call='02312345678';
$preg_call='/^(0\d{2,3})?(\d{7,8})$/ims';
if(preg_match($preg_call,$call)){
    echo 1;
}else{
    echo 0;
}

4、只包含中英文的名字

$name='dfdd';
$preg_name='/^[\x{4e00}-\x{9fa5}]{2,10}$|^[a-zA-Z\s]*[a-zA-Z\s]{2,20}$/isu';
if(preg_match($preg_name,$name)){
    echo 1;
}else{
    echo 0;
}

5、身份证号码

$IDCard='';
$preg_card='/^\d{15}$)|(^\d{17}([0-9]|X)$/isu';
if(preg_match($preg_card,$IDCard)){
    echo 1;
}else{
    echo 0;
}

6、银行卡号

$bankcard='';
$preg_bankcard='/^(\d{15}|\d{16}|\d{19})$/isu';
if(preg_match($preg_card,$bankcard)){
    echo 1;
}else{
    echo 0;
}

7、QQ

$QQ='';
$preg_QQ='/^\d{5,12}$/isu';
if(preg_match($preg_QQ,$QQ)){
    echo 1;
}else{
    echo 0;
}

8、微信

$wechat='cdxcfvsd515d5___1';
$preg_wechat='/^[_a-zA-Z0-9]{5,19}+$/isu';
if(preg_match($preg_wechat,$wechat)){
    echo 1;
}else{
    echo 0;
}

9、特殊符号(如需要验证其他字符,自行转义 "\X" 添加)

$spacial='^%**Y*(';
$preg_spacial="/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\/|\;|\\' | \`|\-|\=|\\\|\|/isu";
if(preg_match($preg_spacial,$spacial)){
    echo 1;
}else{
    echo 0;
}

 

你可能感兴趣的:(PHP(转))