Home > php教程 > php手册 > body text

php手机号码验证判断函数(170和180号段)

WBOY
Release: 2016-05-25 16:47:35
Original
1604 people have browsed it

最简单的最实用的php手机号码正则表达式,有需要的朋友可参考参考.

移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188

联通:130、131、132、152、155、156、185、186

电信:133、153、180、189、(1349卫通)

手机号规则实例代码如下:

$regex = "/13[0-9]{9}|15[0|1|2|3|5|6|7|8|9]\d{8}|17[0|1|2|3|5|6|7|8|9]\d{8}|18[0|5|6|7|8|9]\d{8}/";
Copy after login

判断手机号码实例代码如下:

function is_mobile($str){ 
    return preg_match("/^(((\d{3}))|(\d{3}-))?13\d{9}$/", $str); 
}
Copy after login

实例代码如下:

<?php
function checkMobile($str) {
    $pattern = "/^(13|15|17|18)\d{9}$/";
    if (preg_match($pattern, $str)) {
        Return true;
    } else {
        Return false;
    }
}
//调用函数
$str = checkMobile("15800000001");
if ($str) {
    echo ("符合手机号码标准");
} else {
    echo ("不符合手机号码标准");
}
?>
Copy after login

最后完全可以验证目前所有手机号代码

实例代码如下:

preg_match_all($regex,$row[&#39;mobile&#39;], $phones); 
if($phones){ 
    正确 
}
Copy after login

友情提示,现在关于手机判断的,确实不太好做了,因为手机号码变化已经比较大了.可能今天你写了正则,明天就出了新的号码段了,做个手机号码段数组的,判断是否在号码段内数组=array(130,131,132.....)in_array(substr(号码,0,3),数组)


提示:新增180号段和170号段。

本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!