@@ -571,6 +571,16 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
571
571
"AT" : "43" ,
572
572
}
573
573
574
+ # Handle leading zero in local numbers
575
+ if region not in ["US" , "CA" ] and phone .startswith ("0" ):
576
+ # Remove the leading zero
577
+ phone = phone [1 :]
578
+
579
+ # Fix Austrian phone number duplication issue before processing
580
+ if region == "AT" and "4343" in phone :
581
+ # Remove the duplicated country code
582
+ phone = phone .replace ("4343" , "43" )
583
+
574
584
# If phone is already normalized, return as it is
575
585
expected_country_code = country_codes .get (region )
576
586
if (
@@ -581,11 +591,6 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
581
591
):
582
592
return phone
583
593
584
- # Fix Austrian phone number duplication issue before processing
585
- if region == "AT" and "4343" in phone :
586
- # Remove the duplicated country code
587
- phone = phone .replace ("4343" , "43" )
588
-
589
594
# Sub out anything that matches this regex statement with an empty string to get rid of extensions in generated phone numbers
590
595
phone = re .sub (r"\s*(?:x|ext)\s*\d*$" , "" , phone , flags = re .IGNORECASE )
591
596
# Sub out anything that is not a digit with the empty string to ensure the phone number is formatted with no spaces or special characters
@@ -603,11 +608,6 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
603
608
# Remove country code from the local number
604
609
local_number = digits [len (country_code ) :]
605
610
606
- # Handle leading zero in local numbers
607
- if region not in ["US" , "CA" ] and local_number .startswith ("0" ):
608
- # Remove the leading zero
609
- local_number = local_number [1 :]
610
-
611
611
# Validate local number length
612
612
if len (local_number ) < 6 : # Too short to be valid
613
613
logging .warning (f"Invalid phone number format: { phone } " )
0 commit comments