Basis
According to the October 2017 latest mobile phone number is coded, is the following:
(13\d|14[579]|15[^4\d]|17[^49\d]|18\d) \d{8}
Code
#-*-Coding:utf-8-*-
import random
def create_phone ():
# second digit
second = [3, 4, 5, 7, 8][random.randint ( 0, 4)]
# third digit
third = {
3:random.randint (0, 9),
4: [5, 7, 9][random.randint (0, 2)],
5: [I for I in Range (a) if I!= 4][random.randint (0, 8)],
7: [I for I in range (ten) if I not in [4, 9]][random.randint (0, 7)],
8:random.randint (0, 9),
}[second]
# last eight digits
suffix = random.randint (9999999,100000000)
# splicing cell phone number Return
"1{}{}{}". Format (second, third, suffix)
# Generate phone number of mobile
= Create_phone ()
print (phone)
Run Results
13937342780
15835720604
14589505530
...
validation (using regular authentication)
#-*-Coding:utf-8-*-
import random
import re
def create_phone ():
# second digit
second = [3, 4, 5, 7, 8][r Andom.randint (0, 4)]
# third digit
third = {
3:random.randint (0, 9),
4: [5, 7, 9][random.randint (0, 2)],
5: [I for I in range (Ten) if I!= 4][random.randint (0, 8)],
7: [I for I in range (ten) if I not in [4, 9]][random.randin T (0, 7)],
8:random.randint (0, 9),
}[second]
# last eight digits
suffix = random.randint (9999999,100000000)
# splicing Mobile phone number return
"1{}{}{}". Format (second, third, suffix
) # Generate mobile phone number
= Create_phone (
) print (phone)
# regular
reg = Re.compile ("(13\d|14[579]|15[^4\d]|17[^49\d]|18\d) \d{8}")
print ("Test passed!" if Reg.match ( Phone) Else "Test failed!")
Validation Results
18662182464
Test passed!
15896505277
Test passed!
14952715286
Test passed!
...