PHP正则匹配联系方式手机号、QQ、微信、邮箱、固定电话
function contact($str=\'\'){
if(!$str) die;
$phone = \'/^1[345789]\d{9}$/ims\';//手机号匹配
$qq = \'/^\d{5,12}$/isu\';
$email = \'/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@([a-zA-Z0-9]+[-.])+([a-z]{2,5})$/ims\';
$wchat = \'/^[_a-zA-Z0-9]{5,19}+$/isu\';
$tel = "/^([0-9]{3,4}-)?[0-9]{7,8}$/";
if(preg_match($phone,$str)){
echo \'手机\';
}else if(preg_match($qq,$str)){
echo \'QQ\';
}else if(preg_match($email,$str)){
echo \'邮箱\';
}else if(preg_match($wchat,$str)){
echo \'微信\';
}else if(preg_match($tel,$str)){
echo \'座机\';
}else{
echo \'未知\';
}
}
$a = contact(\'010-7041210\');
echo $a;
————————————————
版权声明:本文为CSDN博主「猿学」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_38787928/article/details/105540431