1
头图

Regular development history of mobile phone number

At that time, considering that operators would only provide mobile phone numbers in certain number segments, the regular expression looks like the following:

/^1([38]\d|5[0-35-9]|7[3678])\d{8}$/

It can be seen that it is used to match the numbers 13X, 18X, 15X, and 17X.

Later, due to insufficient mobile phone numbers, mobile phone numbers for segments 166, 198, and 199 were added, so the regular expression should be improved accordingly:

/^1([38][0-9]|5[0-35-9]|6[6]|7[0135678]|9[89])\d{8}$/

Up to now, the new mobile phone number segment is outrageous, forcing us to use simple and rude verification methods:

/^1(3|4|5|6|7|8|9)\d{9}$/

// 或者
/^1[3456789]d{9}$/

In the future, if you have a 12X mobile phone number, just write it like this:

/^\d{11}$/

With the increasing number of mobile phone numbers, we have given up some pursuits while gaining simplicity. simple life.

So, what if you want to verify the international mobile phone number? First, do a survey:

The number of mobile phone numbers varies from country to country. Including Hong Kong is not the same as the mainland, Hong Kong is 8th.
Germany is 10
11th place in Japan
Canada is the same as a landline phone, 7 digits
New Zealand is usually 9 digits
11th place in the UK
10 digits of Taiwan's mobile phone number
Ten in India
7th place in the UAE
Switzerland 10
Singapore’s mobile phone number is 8 digits like a landline phone
Both Dutch mobile phones and landline phones are 10 digits
Belgium’s mobile phone number is 10 digits
Thailand: 9-digit number
10 of France

It seems that we can only check a number in the range of 5-11:

/^\d{5,11}$/

What if the landline number is to be verified again? When you hear this, you may have to say: fuck it. But still did not hold back to check the composition rules of the landline number:

(Our country's special service phone starts with 1 and ordinary fixed-line telephone starts with 2-9)
The landline number can have 3 digits area code + 8 digits local number + extension number (1 to 4 digits)
Or 4 digits area code + 7 digits local number + extension number (1 to 4 digits)
The area code and extension number may not exist, so the regularity:

 /^((([0-9]{3}-)?[0-9]{8})|(([0-9]{4}-)?[0-9]{7}))(-[0-9]{1,4})?$/

link to the original text


来了老弟
508 声望31 粉丝

纸上得来终觉浅,绝知此事要躬行