Home > Backend Development > PHP Tutorial > PHP mobile phone number regular expression test program code_PHP tutorial

PHP mobile phone number regular expression test program code_PHP tutorial

WBOY
Release: 2016-07-21 14:51:37
Original
856 people have browsed it

The code is as follows

Function funcMtel($str)//Mobile phone number regular expression test

 {

Return (preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))?true:false;

 }

Test

 18678785887

Return to

false

Cause analysis, after checking it, I found that the above regular expression can only verify those starting with 13,15, naturally those starting with 18 cannot be used

After modification

The code is as follows

Function funcMtel($str)//Mobile phone number regular expression test

 {

 return (preg_match("/(?:1[3|4|5|8]d{1}|15[03689])d{8}$/",$str))?true:false;

 }

Test

 18678785887

Return to

true

This will be successful,

Summary of experience:

Number segments such as mobile phone numbers will be constantly updated. When we write the function, we write it as a public function, so that we can solve this problem.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371797.htmlTechArticleThe code is as follows function funcMtel($str)//Mobile phone number regular expression try { return (preg_match(/(?: 13d{1}|15[03689])d{8}$/,$str))?true:false; } Test 18678785887 returns false Cause analysis...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template