+ 1
can someone help me in python3 re module (phone number validation)?
i have a problem with only one case in the phone number validation and it's make me little nervous can some one explain to me how i pass that and where is the problem in my code? mission: ``` Phone Number Validator 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 ``` my code: ``` import re number_from_user = input() pattern = r"\A(1|8|9)\d{7}" res = re.search(pattern, number_from_user) if res: print("Valid") else: print("Invalid") ```
3 ответов
+ 4
Your pattern is incorrect.
You don't need the \A
189 should be in a single class [ ], not an ORed group ()
\d{7} this part is correct
Now you just need to add the 'match end' metacharacter.
+ 1
@ChaoticDawg ohhhhhh i was so stupid bro thank you so much for your help !
0
import re
#your code goes here
num=input()
pat=r"^1|8|9"
if len(num)==8:
if re.match(pat,num):
print("Valid")
else:
print("Invalid")
else:
print("Invalid")