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

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

May 25, 2016 pm 04:47 PM
mobile

最简单的最实用的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号段。

本文地址:

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

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)