@@ -112,6 +112,19 @@ def __init__(self):
112112 "Belgium" : "België" ,
113113 "Austria" : "Österreich" ,
114114 }
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+ }
115128
116129 self .fake = None
117130 self .locale = None
@@ -556,22 +569,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
556569 str
557570 The normalized phone number in the format <country-code><number>.
558571 """
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
575573 if region not in ["US" , "CA" ] and phone .startswith ("0" ):
576574 # Remove the leading zero
577575 phone = phone [1 :]
@@ -582,7 +580,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
582580 phone = phone .replace ("4343" , "43" )
583581
584582 # 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 )
586584 if (
587585 expected_country_code
588586 and phone .isdigit ()
@@ -597,7 +595,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
597595 digits = re .sub (r"\D" , "" , phone )
598596
599597 # Determine country code
600- country_code = country_codes .get (
598+ country_code = self . country_codes .get (
601599 region , "1"
602600 ) # Default to "1" (US/CA) if the region is unknown
603601 # handle leading zeros
@@ -608,6 +606,11 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
608606 # Remove country code from the local number
609607 local_number = digits [len (country_code ) :]
610608
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+
611614 # Validate local number length
612615 if len (local_number ) < 6 : # Too short to be valid
613616 logging .warning (f"Invalid phone number format: { phone } " )
0 commit comments