Last active
September 7, 2019 03:04
-
-
Save nathan-cruz77/06e8c4f263f22fcec4777dd117063e9b to your computer and use it in GitHub Desktop.
E.164 phone number validator
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
import re | |
# Validates whether a phone number is in E.164 (https://en.wikipedia.org/wiki/E.164) | |
# format. | |
# | |
# Sample usage: | |
# | |
# >>> is_e164('55 (12) 98154-1281') | |
# True | |
# | |
# >>> is_e164('800 555 2233') | |
# True | |
# | |
# >>> is_e164('0800 123 4567') | |
# False | |
# | |
def is_e164(number): | |
exp = re.compile('\+?[1-9]\d{1,14}') | |
number = ''.join(c for c in number if c.isdigit()) | |
return exp.match(number) is not None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment