+ 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")8 Antworten
+ 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;
^^^^^^
+ 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.
+ 1
[En]moVes
num = int(input())
print(len(num))
+ 1
Sreeju Not from you, but from him in the original code
0
Obviously, because there was no check on the length of the number
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.
0
Lothar I checked his code, he considers valid too short numbers.
I think it shouldn't be like this...