+ 1

i solve this problem by this way, do u have another idea?

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 https://code.sololearn.com/ccSN3655lODv/?ref=app

19th May 2021, 8:22 AM
karimireza77
karimireza77 - avatar
4 Answers
+ 4
the task can also be done without using regex: inp = input() if len(inp) == 8 and inp.isdigit() and inp[0] in "189": print("Valid") else: print("Invalid")
19th May 2021, 10:42 AM
Lothar
Lothar - avatar
+ 2
TheWh¡teCat 🇧🇬 it said give me a number input, if saif give me a input my programme be different
19th May 2021, 10:47 AM
karimireza77
karimireza77 - avatar
+ 2
Lothar thank you, đŸ»
19th May 2021, 10:48 AM
karimireza77
karimireza77 - avatar
+ 1
karimireza77 , your pattern is not good, it only checks the beginning of the number. If you test it with "1qqqqqqq" it will print "Valid", which obviously is not true.
19th May 2021, 9:32 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar