0
Phone Number Validator
Whats wrong with my code? You are given a number input, and need to check if it is a valid phone number. A valid phone number has exactly 8 digits and starts with 1, 8 or 9. Output "Valid" if the number is valid and "Invalid", if it is not. Sample Input 81239870 Sample Output Valid import re #your code goes here number=input() pattern=r"^{1|8|9}" match= re.match(pattern, number) if match and len(number)==8: print("Valid") else: print("Invalid")
5 Réponses
+ 1
Lisa Ooooooooo, I see. Yeah, mentioning the Course/Lesson name would've saved me the questioning LOL
0
Are you getting a particular error?
Also, it's interesting you're using Regex. I would've just accessed the first character of the string.
Ah, nevermind, syntax error like Lisa said.
0
Thanks Lisa, it seems this was the problem.
0
another solution
import re
#your code goes here
number = input()
pattern = r"^[189]+\d{7}quot;
match =re.match(pattern,number)
if match:
print("Valid")
else:
print("Invalid")