diff options
| author | Bobby <[email protected]> | 2022-10-06 18:35:43 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-10-06 18:35:43 -0400 |
| commit | f79c2e86a9f97737abe1325b76c610c87b7c0d0c (patch) | |
| tree | 8fb6c3d2ff69564fe25cc4c1dce219dbcfa8b28d | |
| parent | 155f2499d15bab010e79b24f96d77758a87b7bbc (diff) | |
| download | edify-f79c2e86a9f97737abe1325b76c610c87b7c0d0c.tar.xz edify-f79c2e86a9f97737abe1325b76c610c87b7c0d0c.zip | |
Fixed validation for special phone numbers
| -rw-r--r-- | src/edify/library/phone.py | 3 | ||||
| -rw-r--r-- | tests/test_phone.py | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/edify/library/phone.py b/src/edify/library/phone.py index 90ab535..362fa97 100644 --- a/src/edify/library/phone.py +++ b/src/edify/library/phone.py @@ -1,6 +1,7 @@ import re pattern = "^\\+?\\d{1,4}?[-.\\s]?\\(?\\d{1,3}?\\)?[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,9}$" +special_pattern = r"^\d{2,4}" def phone_number(phone: str) -> bool: @@ -12,7 +13,7 @@ def phone_number(phone: str) -> bool: bool: True if the string is a valid phone number, False otherwise. """ - if re.match(pattern, phone): + if re.match(pattern, phone) or re.match(special_pattern, phone): return True else: return False diff --git a/tests/test_phone.py b/tests/test_phone.py index 8c95d60..cbff29c 100644 --- a/tests/test_phone.py +++ b/tests/test_phone.py @@ -18,7 +18,8 @@ def test(): "+1 (124) 232": True, "+1 (123) 45-890": True, "+1 (1) 456-7890": True, - "9012": False, + "9012": True, + "911": True, "+1 (615) 243-": False } for phone, expectation in phones.items(): |
