php验证手机号

时间:2022-11-06 19:30:55


1.实现代码如下

        /**
 * 验证手机号
 * @param  [type] $tel [description]
 * @return [type]      [description]
 */
function validatePhoneno($tel){
//正则表达式 
if(strlen($tel) == "11"){ 
//上面部分判断长度是不是11位 
$n = preg_match_all("/13[123569]{1}\d{8}|15[1235689]\d{8}|188\d{8}/",
$tel,$array); 
/*接下来的正则表达式("/131,132,133,135,136,139开头随后跟着任意的8为数字 '|
'(或者的意思) 
 * 151,152,153,156,158.159开头的跟着任意的8为数字 
 * 或者是188开头的再跟着任意的8为数字,匹配其中的任意一组就通过了 
 * /")*/
if (empty($array)) {
return false;
}

return true;
}else{ 
    return false;

}