aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/edify/library/__init__.py2
-rw-r--r--src/edify/library/phone.py17
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