- 1

Why does an error keep showing up

im trying to do the phone validation challenge i don't even know what's wrong with it and the error message barely helps me import re pn = int(input()) pattern = r"[1,8,9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" if re.match(pattern, pn): print("Valid") else: print("Invalid")

11th Dec 2021, 11:15 PM
Ricinoob
Ricinoob - avatar
4 odpowiedzi
+ 3
may be you modify the issues with in() input, the pattern and also a check for 8 digits is reqired: import re pn = input() # use string as input pattern = r"[189]+[0-9]" # you can use this pattern if re.match(pattern, pn) and len(pn) == 8: # check for 8 digits print("Valid") else: print("Invalid")
12th Dec 2021, 10:50 AM
Lothar
Lothar - avatar
+ 1
The comma character appears twice in r"[1,8,9]" It should be r"[189]"
11th Dec 2021, 11:58 PM
Angelo
Angelo - avatar
0
phone number validator**
11th Dec 2021, 11:16 PM
Ricinoob
Ricinoob - avatar
0
I see others explained other your problems so i can just recommend to change your pattern to: r"^[189][\d]{7}
quot; as it looks better for potential readers and helps you with further changes.
12th Dec 2021, 7:33 AM
Herr Rozwel
Herr Rozwel - avatar