- 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")
4 Answers
+ 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")
+ 1
The comma character appears twice in r"[1,8,9]"
It should be r"[189]"
0
phone number validator**
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.