Created
December 9, 2018 18:47
-
-
Save serpent213/6a45ed6adf8797fef9cccb8a5b0db2ab to your computer and use it in GitHub Desktop.
validate phone number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def isPhoneNumber(text): | |
if len(text) != 11: | |
return False | |
for i in range(0,3): | |
if not text[i].isdigit(): | |
return False | |
if text[3] != '-': | |
return False | |
for i in range(4,7): | |
if not text[i].isdigit(): | |
return False | |
if text[7] != '-': | |
return False | |
for i in range(8,11): | |
if not text[i].isdigit(): | |
return False | |
return True | |
print('666 666 666 is a phone number: ') | |
print(isPhoneNumber('666-666-666')) | |
print('Moshi moshi is a phone number') | |
print(isPhoneNumber('Moshi moshi')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Play around with the interactive shell to see how exactly the ranges expand: