+ 1

Python core - Phone Number Validator

Hi! Need help with task listed in topic. Why that code don't pass tests? import re #your code goes here phone_number = input() pattern = r"^1|8|9[0-9]{7}

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

3rd Sep 2022, 6:31 PM
Damian Hennek
Damian Hennek - avatar
8 odpowiedzi
+ 7
try the pattern in this way: (we need to use a character group) pattern = "^[1|8|9][0-9]{7}
quot; ^^^^^^^ or: pattern = r"^[189][0-9]{7}
quot; ^^^^^^
3rd Sep 2022, 8:18 PM
Lothar
Lothar - avatar
+ 3
[En]moVes , the check for the length was done in the initial code: {7} is a quantifier that defines that the previous characters has to be of length 7. the length of the starting numer is 1. so in total we have defined a length of 8 characters.
4th Sep 2022, 6:12 AM
Lothar
Lothar - avatar
+ 1
[En]moVes num = int(input()) print(len(num))
3rd Sep 2022, 7:02 PM
Sreeju
Sreeju - avatar
+ 1
Sreeju Not from you, but from him in the original code
3rd Sep 2022, 7:17 PM
Евгений Молдованов
Евгений Молдованов - avatar
0
Obviously, because there was no check on the length of the number
3rd Sep 2022, 6:49 PM
Евгений Молдованов
Евгений Молдованов - avatar
0
I tought that pattern limited to 8 characters is enough. Pattern start from 1 or 8 or 9 and then we have 7 digits between 0-9, that gives 8 characters.
3rd Sep 2022, 7:25 PM
Damian Hennek
Damian Hennek - avatar
0
Lothar I checked his code, he considers valid too short numbers. I think it shouldn't be like this...
4th Sep 2022, 6:37 AM
Евгений Молдованов
Евгений Молдованов - avatar