search
Homephp教程php手册php手机号码验证判断函数

php手机号码验证判断函数

Jun 13, 2016 am 10:15 AM
phpfunctionjudgmentCanphone numberhavefriendregularuseofexpressionverify

最简单的最实用的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}|18[0|5|6|7|8|9]d{8}/";

例1

判断手机号码:

 代码如下 复制代码

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

实例

 代码如下 复制代码


 function checkMobile($str)
 {
     $pattern = “/^(13|15)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['mobile'], $phones);
if($phones){
    正确
}

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool