-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValid_phone_number.py
More file actions
28 lines (24 loc) · 882 Bytes
/
Valid_phone_number.py
File metadata and controls
28 lines (24 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# In the name of God
# Mohammad Hossein Zehtab
# Advanced-Python-Wednesdays
# Regex: Valid_phone_number
import re
def is_valid_phone_number(phone_number : str):
"""
Checking if a phone number is valid or not.
"""
# pattern = r"\+\d+(([ -.]\d+){3}|( \(\d{3}\) \d+))?"
pattern = r"^(\+\d{1,3})?[\s.-]?\(?\d{1,4}\)?[\s.-]?\d{3}[\s.-]?\d{4}$"
result = re.fullmatch(pattern=pattern, string=phone_number)
print("Valid") if result else print("Not Valid")
### Driver Code ###
is_valid_phone_number("+98.912.717.5477")
is_valid_phone_number("+98 912 717 5477")
is_valid_phone_number("+98-912-717-5477")
is_valid_phone_number("+989127175477")
is_valid_phone_number("+98 (912) 7175477")
print()
is_valid_phone_number("98 912 717 5477")
is_valid_phone_number("+98912717")
is_valid_phone_number("+98 912 p17 5477")
is_valid_phone_number("+44 (0) 20 234 5678")