Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions persian_tools/phone_number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

MOBILE_REGEX = '(?:[+|0{2}]?98)?(?:0)?(\\d{3})+(\\d{3})+(\\d{4})'
VALID_TOKENS = ['+98', '98', '0098', '0']
MOBILE_SUFFIX_REGEX = '^(?:\+98|98|0098|0)'
MOBILE_SUFFIX_REGEX = r'^(?:\+98|98|0098|0)'


def _get_operator_data(phone_number: str) -> Union[dict, bool]:
Expand All @@ -19,8 +19,14 @@ def _get_operator_data(phone_number: str) -> Union[dict, bool]:


def validate(phone_number: str) -> bool:
return _get_operator_data(phone_number) is not False
operator = _get_operator_data(phone_number)
if not operator:
return False

if not re.fullmatch(MOBILE_REGEX, phone_number):
return False

return True

def operator_data(phone_number: str) -> bool:
res = _get_operator_data(phone_number)
Expand Down