+ 2

What's wrong with this phone number validator regex?

This is the task: 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. What is wrong with the following regex? import re number = input() pattern = r"^1|8|9\d{8}

quot; if re.match(pattern, number): print("Valid") else: print("Invalid")

5th Nov 2022, 7:52 AM
guy bino
guy bino - avatar
2 ответов
+ 9
^(1|8|9)\d{7}$ start with 1 or 8 or 9 , next 7 digit
5th Nov 2022, 8:10 AM
Roland
Roland - avatar
+ 2
Thank you Roland 🙏
5th Nov 2022, 9:28 AM
guy bino
guy bino - avatar