Home  >  Article  >  php教程  >  php中手机号码正则表达式代码

php中手机号码正则表达式代码

WBOY
WBOYOriginal
2016-06-08 17:24:161060browse

我们的手机号现在分类中国移动与中国联通了,下面我来给大家先分析他们的特性,然后进行有效的编码。

<script>ec(2);</script>

手机(中国移动手机号码):

 代码如下 复制代码
regexp="^(((d{3}))|(d{3}-))?13[456789]d{8}|15[89]d{8}"

验证是否为手机号码的正则

 代码如下 复制代码
:"^(13[0-9]|15[0|3|6|7|8|9]|18[6|8|9])d{8}$"

php代码

 代码如下 复制代码

$regex = '/^1((3[0-9])|(4[57])|(5[012356789])|(8[02356789]))[0-9]{8}$/';

if (preg_match($regex, $mobilePhone) == 0) {
    //error
}

else

{
   echo '有效的手机号码';
}
?>

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