- 2

how can i solve phone number validation in python(regular expression)

6th Jun 2021, 6:12 PM
Md Shakil
Md Shakil - avatar
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
6th Jun 2021, 9:41 PM
Ervis Meta
Ervis Meta - avatar
0
It also doesn't work bro Ervis
6th Jun 2021, 9:51 PM
Md Shakil
Md Shakil - avatar
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
6th Jun 2021, 9:54 PM
Ervis Meta
Ervis Meta - avatar
0
But why?
6th Jun 2021, 9:56 PM
Md Shakil
Md Shakil - avatar
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 ...
6th Jun 2021, 9:59 PM
Ervis Meta
Ervis Meta - avatar
0
# oneliner: print("Valid" if re.fullmatch("[189].{7}", input()) else "Invalid")
6th Jun 2021, 10:56 PM
visph
visph - avatar