+ 2
Got a question for Python “Phone number validator”
You need to find a phone number in the input where it matches the following pattern: It should starts with 1 or 8 or 9 , and the length should be 8 /// import re #your code goes here num = input() pat = r"^[189](/d){7}
quot; if re.match(pat, num): print("Valid") else: print("Invalid") /// So I did this, and somehow it’s wrong. but when I tried pat = r”^[189][0-9]{7}$” and it worked. Could you teach me what’s the difference? I thought /d also means any digits from 0 to 9.3 ответов
+ 8
pat = r"^[189]\d{7}quot; #debug
+ 3
Vasiliy I feel so stupid right now lol thanks for the answer!
0
Hello guys I can't figure out why Phone Number Validator question of Sololearn can't be solved on the page. This code works on any python editor but refuses on the sololearn page.
This is my code. Anyone who can help me?
import re
#your code goes here
number="57345672"
pattern=r"^[1|8|9]\d{7}quot;
match= re.match(pattern,number)
if(match):
print ("Valid")
else:
print("Invalid")