diff options
| author | Bobby <[email protected]> | 2022-08-31 00:04:23 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-08-31 00:04:23 -0400 |
| commit | c6344afd77b8bf5baeb67fee8270ca24c555ec6c (patch) | |
| tree | a0e7151ec44c05969ae95ee6c969980160577d1c /src | |
| parent | d909b5d264b7244dbf7d74970e4b34be9181bb9b (diff) | |
| download | edify-c6344afd77b8bf5baeb67fee8270ca24c555ec6c.tar.xz edify-c6344afd77b8bf5baeb67fee8270ca24c555ec6c.zip | |
Added Phone Number Validation
Diffstat (limited to 'src')
| -rw-r--r-- | src/edify/library/__init__.py | 2 | ||||
| -rw-r--r-- | src/edify/library/phone.py | 17 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/edify/library/__init__.py b/src/edify/library/__init__.py index 88f67d1..549cd4c 100644 --- a/src/edify/library/__init__.py +++ b/src/edify/library/__init__.py @@ -1,3 +1,5 @@ # flake8: noqa +# Import everything from the library. +from .phone import phone_number from .mail import email diff --git a/src/edify/library/phone.py b/src/edify/library/phone.py new file mode 100644 index 0000000..5c271af --- /dev/null +++ b/src/edify/library/phone.py @@ -0,0 +1,17 @@ +import re + +pattern = "^\\+?\\d{1,4}?[-.\\s]?\\(?\\d{1,3}?\\)?[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,9}$" + +def phone_number(phone: str) -> bool: + """Checks if a string is a valid phone number. + + Args: + phone (str): The string to check. + Returns: + bool: True if the string is a valid phone number, False otherwise. + """ + + if re.match(pattern, phone): + return True + else: + return False |
