I can't pass Test Case 3 in Code Project – Phone Number Validator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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')

26th Dec 2021, 11:58 AM
Lyapunov Alexander
Lyapunov Alexander - avatar
3 Answers
+ 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
26th Dec 2021, 4:38 PM
Lothar
Lothar - avatar
+ 1
Ok, thank you very much. It's very useful.
26th Dec 2021, 2:58 PM
Lyapunov Alexander
Lyapunov Alexander - avatar
+ 1
Yes, I used pattern = r'^[189]\d{7}
#x27; and it correctly.
26th Dec 2021, 4:54 PM
Lyapunov Alexander
Lyapunov Alexander - avatar