Teddy Xinyuan Chen
commited on
2024-05-19T13-48-30Z
Browse files
app.py
CHANGED
@@ -34,14 +34,20 @@ keypad_mapping = {
|
|
34 |
def convert_phone_number(phone_number, trim_to_10):
|
35 |
numerical_phone_number = ""
|
36 |
digit_count = 0
|
|
|
|
|
37 |
for char in phone_number:
|
38 |
if char.isalpha():
|
39 |
numerical_phone_number += keypad_mapping[char.upper()]
|
40 |
-
|
|
|
|
|
41 |
else:
|
42 |
numerical_phone_number += char
|
43 |
-
if char.isdigit():
|
44 |
digit_count += 1
|
|
|
|
|
45 |
if trim_to_10 and digit_count >= 10:
|
46 |
break
|
47 |
return numerical_phone_number
|
|
|
34 |
def convert_phone_number(phone_number, trim_to_10):
|
35 |
numerical_phone_number = ""
|
36 |
digit_count = 0
|
37 |
+
ignore_first_digit = phone_number.startswith("1")
|
38 |
+
|
39 |
for char in phone_number:
|
40 |
if char.isalpha():
|
41 |
numerical_phone_number += keypad_mapping[char.upper()]
|
42 |
+
if not ignore_first_digit:
|
43 |
+
digit_count += 1
|
44 |
+
ignore_first_digit = False
|
45 |
else:
|
46 |
numerical_phone_number += char
|
47 |
+
if char.isdigit() and not (ignore_first_digit and digit_count == 0):
|
48 |
digit_count += 1
|
49 |
+
ignore_first_digit = False
|
50 |
+
|
51 |
if trim_to_10 and digit_count >= 10:
|
52 |
break
|
53 |
return numerical_phone_number
|