This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphonenumber.py
92 lines (70 loc) · 3.48 KB
/
phonenumber.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
USA = 0
COUNTRY_CODES = [
"1", "20", "212", "213", "216", "218", "220", "221", "222", "223",
"224", "225", "226", "227", "228", "229", "230", "231", "232", "233",
"234", "235", "236", "237", "238", "239", "240", "241", "242", "243",
"244", "245", "246", "247", "248", "249", "250", "251", "252", "253",
"254", "255", "256", "257", "258", "260", "261", "262", "263", "264",
"265", "266", "267", "268", "269", "27", "290", "291", "297", "298",
"299", "30", "31", "32", "33", "34", "350", "351", "352", "353",
"354", "355", "356", "357", "358", "359", "36", "370", "371", "372",
"373", "374", "375", "376", "377", "378", "380", "381", "385", "386",
"387", "389", "39", "40", "41", "420", "421", "423", "43", "44",
"45", "46", "47", "48", "49", "500", "501", "502", "503", "504",
"505", "506", "507", "508", "509", "51", "52", "53", "5399", "54",
"55", "56", "57", "58", "590", "591", "592", "593", "594", "595",
"596", "597", "598", "599", "60", "61", "618", "62", "63", "64",
"65", "66", "670", "672", "673", "674", "675", "676", "677", "678",
"679", "680", "681", "682", "683", "684", "685", "686", "687", "688",
"689", "690", "691", "692", "7", "808", "81", "82", "84", "850",
"852", "853", "855", "856", "86", "870", "871", "872", "873", "874",
"878", "880", "881", "8816", "8817", "88213", "88216", "886", "90", "91",
"92", "93", "94", "95", "960", "961", "962", "963", "964", "965",
"966", "967", "968", "970", "971", "972", "973", "974", "975", "976",
"977", "98", "992", "993", "994", "995", "996", "998"
]
REASONS = [
"Phone Number Too Long or Too Short",
"US Number must be length 10",
"Unknown Country Code"
]
class PhoneNumber():
def __init__(self, original_value):
self.original_value = original_value
self.country_code_index = USA
self.stripped_value = None
self.invalid_reason = None
def get_value_as_international(self) -> str:
return get_value_as_international(self.country_code_index,
self.stripped_value)
def get_value_as_north_america(self) -> str:
return get_value_as_north_america(self.country_code_index,
self.stripped_value)
def is_valid(self) -> bool:
return self.invalid_reason is None
def is_north_america_number(self) -> bool:
return self.country_code_index == USA
def strip_phone_number(number: str) -> str:
return ""
def get_country_code_index(stripped_number: str) -> int:
return -1
def validate(country_code_index: int, stripped_number: str) -> str:
return validate_north_america(country_code_index, stripped_number) \
if country_code_index == USA \
else validate_international(country_code_index, stripped_number)
def validate_international(country_code_index: int,
stripped_number: str) -> str:
return ""
def validate_north_america(country_code_index: int,
stripped_number: str) -> str:
return "" \
if len(extract_phone_body(country_code_index, stripped_number)) == 10 \
else REASONS[1]
def extract_phone_body(country_code_index: int, stripped_number: str) -> str:
return ""
def get_value_as_international(country_code_index: int,
stripped_number: str) -> str:
return ""
def get_value_as_north_america(country_code_index: int,
stripped_value: str) -> str:
return ""