Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use javascript to verify mobile phone number

Shulou Source: shulou.com Published: 2022-05-31 10:36:51 10月03日 Update

This article mainly explains "how to use javascript to verify mobile phone number", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use javascript to verify mobile phone number"!

Javascript's method to verify the mobile phone number: first create a js code file, and then use the regular expression "return / ^ 1 [3-9]\ d {9} $/ .test (mobile)" to determine whether the mobile phone number is correct.

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

How does javascript verify the mobile phone number?

Regular expression of JavaScript mobile phone number

In our usual development process, we often have to judge a mobile phone number. I remember that when I first started to do the front-end "cutter", I wondered if this was not handled by the back-end. In fact, if the front end judges in advance whether the mobile phone number is correct, it can reduce the latter segment requests and save broadband resources.

We first need to understand the rules of mobile phone numbers "from Baidu Encyclopedia":

China Telecom number range: 133, 149, 153, 173, 177, 180, 181, 189, 191, 199

China Unicom number range: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186

China Mobile number range: 134 (0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 172, 178, 182, 183, 184, 187, 188, 198

Other segments: the 14th paragraph used to be the exclusive number segment of the network card, such as China Unicom 145, China Mobile 147 and so on.

Virtual operator

Telecommunications: 1700, 1701, 1702, 162,

Mobile: 1703, 1705, 1706, 165

Unicom: 1704, 1707, 1708, 1709, 171,167

Satellite Communications: 1349

First of all, the mobile phone number can only be an integer. We can judge like this:

Function isMobile (mobile) {return /\ d+/.test (mobile)}

Then the mobile phone number must start with a number and end with a number, which can be upgraded:

Function isMobile (mobile) {return / ^\ d+$/.test (mobile)}

The above rule can only make a simple judgment. We know that all mobile phone numbers start with 1. You can upgrade the way you write it:

Function isMobile (mobile) {return / ^ 1\ d+$/.test (mobile)}

In addition, the mobile phone numbers are all 11 digits:

Function isMobile (mobile) {return / ^ 1\ d {10} $/ .test (mobile)}

The second digit of the mobile phone number is the number from 3 to 9:

Function isMobile (mobile) {return / ^ 1 [3-9]\ d {9} $/ .test (mobile)} Thank you for your reading, the above is the content of "how to use javascript to verify mobile phone numbers". After the study of this article, I believe you have a deeper understanding of how to use javascript to verify mobile phone numbers, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Mobile phone number Mobile number Verification number range China number Writing Rule Learning Mobile China Mobile content Front end beginning Telecom expression China Unicom upgrade Network Card Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi vpn Linux Shulou Tech Info