0
Phone validater using python
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
7 Réponses
+ 3
what we need to do is:
basic version
▪︎take the input as string
▪︎check if length is 8. len() is a builtin function that can be also used for string type
▪︎check if all characters are digits. we can use the string method .isdigit()
▪︎check if first character is in "189"
advanced version
▪︎use regex
+ 2
Dawit Yitagesu ,
if you need more help, please show us your code.
thanks!
+ 1
Why not check the first character and then check the length of the string? Or check the length first, it's faster that way
+ 1
Dawit Yitagesu
Use the len() function, just pass in the string and it'll return the length
+ 1
Dawit Yitagesu
I'm not sure how it works in python, but the pattern should look somewhat like this:
^[189]\d{7}$
Make sure to import the re library
0
How can I check the length
0
I was wondering if u guys help me using regx