Home  >  Article  >  Web Front-end  >  Error-prone js mobile phone number verification

Error-prone js mobile phone number verification

php中世界最好的语言
php中世界最好的语言Original
2018-03-29 17:49:581670browse

This time I will bring you the js mobile phone number verification that is prone to errors. What are the precautions for js mobile phone number verification that is prone to errors? The following is a practical case, let’s take a look.

Write a simple regular expression to verify the 11-digit mobile phone number. The beginning is allowed to be 13, 15, and 18. I wrote it like this at the beginning:

var reg = /^(13[0-9]{9})|(15[0-9]{9})|(18[0-9]{9})$/;

Run it and find that even if it is 13988888877157777, can also pass the verification, which means that this writing method is wrong. My original intention is to like this:

 ^(13[0-9]{9})$ 或者 ^(15[0-9]{9})$ 或者 ^(18[0-9]{9})$

So the correct writing method is: var reg = /^1[358][0-9] {9}$/;This is how to ensure 11 digits

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the use of lastIndex in regular expressions

Detailed explanation of the use of balance groups in regular expressions (with code)

The above is the detailed content of Error-prone js mobile phone number verification. For more information, please follow other related articles on the PHP Chinese website!

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