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

javascript - Problem with regular verification of mobile phone number

WBOY
Release: 2016-09-21 14:12:56
Original
1119 people have browsed it

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

<code>    }
    
    </code>
Copy after login
Copy after login

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>
Copy after login
Copy after login
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>
Copy after login
Related labels:
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