- 2
how can i solve phone number validation in python(regular expression)
6 Answers
0
Just check the input for the requirements and print ok if so đ
I bet that you have read carefully how to check with pattern đđ:
p = r'^[189]'
len(a) = 8
0
It also doesn't work bro Ervis
0
i've posted at other your question:
import re
p = r'^[189]'
a = str(input())
if re.match(p,a) and len(a) == 8:
print('valid')
else:
print('invalid')
doesn't this code work 'cause it worked for me
0
But why?
0
That is what says at the first page :
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.
Sample Input
81239870
Sample Output
Valid
So my code should be valid as it fulfills the requirements.
Or maybe there is a bug in your try ...
0
# oneliner:
print("Valid" if re.fullmatch("[189].{7}", input()) else "Invalid")