Generally, the form page needs to fill in the mobile phone number. To verify whether the mobile phone number entered by the user is correct, we need to use the regular expression to match the mobile phone number segment. If it is in the operator number segment, the number is correct. Therefore, it is necessary to know the latest segment number of the operator, as shown below:
Mobile phone number segment of major operators (New)
China telecom signal section
133,153,173,177,180,181,189,190,191,193,199
China Unicom section
130,131,132,145,155,156,166,167,171,175,176,185,186,196
China mobile segment
134(0-8),135,136,137,138,139,1440,147,148,150,151,152,157,158,159,172,178,182,183,184,187,188,195,197,198
China Radio and television section
192
Other segments
Segment 14 is the exclusive segment of the network card: China Unicom 145, China Mobile 147, China Telecom 149
Virtual operators:
Telecommunications: 1700, 1701, 1702, 162
Mobile: 1703, 1705, 1706, 165
Unicom: 1704, 1707, 1708, 1709, 171, 167
Satellite communication: 1349, 174
Internet of things: 140, 141, 144, 146, 148
It can be seen from the above paragraph that the mobile phone number starts with 1, the second digit is any one of 3456789, and the third digit is either 0-9 in the whole paragraph or only part, as follows:
Cell phone numbers beginning with 13 and 18 are full paragraphs
The mobile phone number at the beginning of 13 is the whole paragraph: 13 [0123456789], such as 130131132... 139
The mobile phone number beginning with 18 is the whole paragraph: 18 [0123456789], such as 180181182... 189
The mobile phone numbers beginning with 15 and 19 are followed by all but 4, without 154 and 194
15 [012356789] for example, 150151152153155... 159
19 [012356789] for example, 190191192193195... 159
The mobile phone number beginning with 17 is followed by 9
17 [01235678] for example, 170171172173... 178
There are all mobile phone numbers starting with 14 Except 2 and 3, without 142 and 143
14 [01456879] for example, 140141144145... 149
The mobile phone number starting with 16 is followed by 2567
16 [2567] for example: 162165166167
After knowing the latest number segment of the operator, write the latest regular expression for mobile phone number verification:
/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])d{8}$/
Examples in javascript:
<script> var reg_user = /^[one-A]{2,4}$/; //2-4 Chinese characters regular var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])d{8}$/; //11 digit mobile phone number function checkSubmit() { if (document.form.user.value =="") { alert("Name cannot be empty!"); document.form.user.focus(); return false; } else if (!reg_user.test(document.form.user.value)) { alert("Name can only be 2-4 chinese!"); document.form.user.focus(); document.form.user.select(); return false; } if (document.form.tel.value =="") { alert("Please fill in your mobile phone number!"); document.form.tel.focus(); document.form.tel.select(); return false; } else if (!reg_tel.test(document.form.tel.value)) { alert("Please fill in your mobile phone number correctly!"); document.form.tel.focus(); document.form.tel.select(); return false; } } </script>
Because mobile phone numbers start with 1, you can also write this:
/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])d{8}$/
This is to write all the operator segments together, including virtual operators and the Internet of things. You can also write them according to the needs of the project.
Common regular expressions for form field validation
1. Name
/^[one-A]{2,4}$/ //2-4 Chinese characters regular
2. Mobile phone number
/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])d{8}$/
3. Landline number
/^(0d{2,3})-?(d{7,8})$/
4. Email address
/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/
5, ID number
(1) General verification
/(^d{15}$)|(^d{18}$)|(^d{17}(d|X|x)$)/
(2) Accurate calibration
18 bits
/^[1-9]d{5}(19|20)d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)d{3}[0-9Xx]$/
15 bits
/^[1-9]d{5}d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)d{2}[0-9Xx]$/
Last 6 digits
/^(([0-2][1-9])|10|20|30|31)d{3}[0-9Xx]$/
6. QQ number
/^[1-9][0-9]d{4,9}$/
7. Postal code
/^[1-9]d{5}$/
8. Registered account
/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/