@@ -112,6 +112,19 @@ def __init__(self):
112
112
"Belgium" : "België" ,
113
113
"Austria" : "Österreich" ,
114
114
}
115
+ # Country code mapping for different regions
116
+ self .country_codes = {
117
+ "US" : "1" ,
118
+ "CA" : "1" ,
119
+ "FR" : "33" ,
120
+ "DE" : "49" ,
121
+ "GB" : "44" ,
122
+ "IT" : "39" ,
123
+ "PL" : "48" ,
124
+ "ES" : "34" ,
125
+ "BE" : "32" ,
126
+ "AT" : "43" ,
127
+ }
115
128
116
129
self .fake = None
117
130
self .locale = None
@@ -556,22 +569,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
556
569
str
557
570
The normalized phone number in the format <country-code><number>.
558
571
"""
559
-
560
- # Country code mapping for different regions
561
- country_codes = {
562
- "US" : "1" ,
563
- "CA" : "1" ,
564
- "FR" : "33" ,
565
- "DE" : "49" ,
566
- "GB" : "44" ,
567
- "IT" : "39" ,
568
- "PL" : "48" ,
569
- "ES" : "34" ,
570
- "BE" : "32" ,
571
- "AT" : "43" ,
572
- }
573
-
574
- # Handle leading zero in local numbers
572
+ # Handle leading zero in local numbers before country code is removed
575
573
if region not in ["US" , "CA" ] and phone .startswith ("0" ):
576
574
# Remove the leading zero
577
575
phone = phone [1 :]
@@ -582,7 +580,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
582
580
phone = phone .replace ("4343" , "43" )
583
581
584
582
# If phone is already normalized, return as it is
585
- expected_country_code = country_codes .get (region )
583
+ expected_country_code = self . country_codes .get (region )
586
584
if (
587
585
expected_country_code
588
586
and phone .isdigit ()
@@ -597,7 +595,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
597
595
digits = re .sub (r"\D" , "" , phone )
598
596
599
597
# Determine country code
600
- country_code = country_codes .get (
598
+ country_code = self . country_codes .get (
601
599
region , "1"
602
600
) # Default to "1" (US/CA) if the region is unknown
603
601
# handle leading zeros
@@ -608,6 +606,11 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
608
606
# Remove country code from the local number
609
607
local_number = digits [len (country_code ) :]
610
608
609
+ # Handle leading zero in local numbers after country code is removed
610
+ if region not in ["US" , "CA" ] and local_number .startswith ("0" ):
611
+ # Remove the leading zero
612
+ local_number = local_number [1 :]
613
+
611
614
# Validate local number length
612
615
if len (local_number ) < 6 : # Too short to be valid
613
616
logging .warning (f"Invalid phone number format: { phone } " )
0 commit comments