+ 1
I have a question about regular expressions and need a little help in my code
It's a phone number validator. The should contain exactly eight numbers and should start with 1,8 or 9. Here's my code import re pattern = r"[1-9] number = input match = re.match(pattern, number) if match: print("Valid") else: print("Invalid") Can anyone please tell me how to make my start with 1 or 8 or 9
3 ответов
+ 3
to validate that number starts with 1,8 or 9 you can try ro put it like this
pattern = r"(1|8|9)[0-9]{7}quot;
+ 1
Philippe Here's a shorter pattern:
r"[189]\d{7}quot;
# Hope this helps
+ 1
Calvin Thomas Great