Home  >  Article  >  Backend Development  >  javascript - Problem with regular verification of mobile phone number

javascript - Problem with regular verification of mobile phone number

WBOY
WBOYOriginal
2016-09-21 14:12:561052browse

if (!preg_match('/0?(00|01|11|13|14|15|17|18)[0-9]{9}/', $tel)) {

<code>    }
    
    </code>

Why does this regular expression allow mobile phone numbers with more than 11 digits to pass through directly without reporting an error? 00 and 01 11 are customized, just ignore them
The regular expression is not very good. What is wrong? How should I write it?

Reply content:

if (!preg_match('/0?(00|01|11|13|14|15|17|18)[0-9]{9}/', $tel)) {

<code>    }
    
    </code>
Why does this regular expression allow mobile phone numbers with more than 11 digits to pass through directly without reporting an error? 00 and 01 11 are customized, just ignore them

The regular expression is not very good. What is wrong? How should I write it?

Because you are useless ^....$ https://secure.php.net/manual...

<code>preg_match('/^(\+86)?1[34578]\d{9}$/',$phone)</code>
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