Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does javascript verify the mobile phone number

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to verify mobile phone numbers in javascript". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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)} "how javascript verifies mobile phone numbers" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report