+ 1
I can't pass Test Case 3 in Code Project – Phone Number Validator
Hello everyone, I need a help. In the block Regular Expressions I can not pass internal Test Case 3. Task: 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 #this is my code tel_number = input() pattern = r"[189]\d{7}" if re.match(pattern, tel_number): print('Valid') else: print('Invalid')
3 Réponses
+ 6
Lyapunov Alexander ,
you have been very close, only '#x27; was missing at the end of the pattern:
pattern = r"[189]\d{7}" # your pattern
pattern = r"[189]\d{7}quot; # correct pattern
+ 1
Ok, thank you very much. It's very useful.
+ 1
Yes, I used pattern = r'^[189]\d{7}#x27; and it correctly.