search
Homephp教程php手册php手机号码验证判断函数(170和180号段)

最简单的最实用的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}/";

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

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

实例代码如下:

<?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 ("不符合手机号码标准");
}
?>

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

实例代码如下:

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

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


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

本文地址:

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.