Because of the use of mobile phone number verification, so simply write a simple phone number verification code.
1 ImportRe2 3 4 defMain ():5Tel = input ("Please enter your phone number:")6 #ret = Re.match (r "1[35678]\d{9}", tel)7 #since the number of mobile phone number is more than 11 bits can also match successfully, so modify the following:8ret = Re.match (r"^1[35678]\d{9}$", tel)9 Ten ifret: One Print("Match Success") A Else: - Print("Match failed") - the - if __name__=="__main__": -Main ()
The "Regular expression" analysis is as follows:
The phone number is 11 bits, so you must limit the number of digits of the matched number to the end of the 9-digit number by the $ limit.
And because the cell phone number starts with 1, so the ^1 limit starts with 1,
Then the mobile phone number second looks like only 3,5,6,7,8, these few numbers, so through [3,5,6,7,8] to match any one of them,
The last {9} matches 9/d.
"Fill":/d indicates matching number
Python-based-use regular expressions to verify phone numbers