@@ -469,6 +469,60 @@ def get_state_province_abbreviation(self, full_name: str) -> str:
469
469
"""
470
470
return self .state_province_abbr .get (full_name , "Not Found" )
471
471
472
+ def normalize_regional_phone_numbers (self , phone : str , region : str ) -> str :
473
+ """
474
+ Normalizes a phone number by separating the country prefix and verifying the rest of the number as an integer.
475
+ This is used for localization (l10n) regional tests.
476
+ Parameters:
477
+ -----------
478
+ phone : str
479
+ The phone number to be normalized.
480
+ region : str
481
+ The region (country) code to determine the correct country prefix.
482
+ Returns:
483
+ --------
484
+ str
485
+ The normalized phone number in the format <country-code><number>.
486
+ """
487
+
488
+ # Country code mapping for different regions
489
+ country_codes = {
490
+ "US" : "1" ,
491
+ "CA" : "1" ,
492
+ "FR" : "33" ,
493
+ "DE" : "49" ,
494
+ }
495
+
496
+ # Sub out anything that matches this regex statement with an empty string to get rid of extensions in generated phone numbers
497
+ phone = re .sub (r"\s*(?:x|ext)\s*\d*$" , "" , phone , flags = re .IGNORECASE )
498
+ # 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
499
+ digits = re .sub (r"\D" , "" , phone )
500
+
501
+ # Determine country code
502
+ country_code = country_codes .get (region , "1" ) # Default to "1" (US/CA) if region is unknown
503
+ local_number = digits
504
+
505
+ # Check if phone already contains a valid country code
506
+ for code in country_codes .values ():
507
+ if digits .startswith (code ):
508
+ country_code = code
509
+ # Remove country code from local number
510
+ local_number = digits [len (code ):]
511
+ break
512
+
513
+ # Handle leading zero in local numbers (France & Germany)
514
+ if region in ["FR" , "DE" ] and local_number .startswith ("0" ):
515
+ # Remove the leading zero
516
+ local_number = local_number [1 :]
517
+
518
+ # Validate local number length
519
+ if len (local_number ) < 6 : # Too short to be valid
520
+ logging .warning (f"Invalid phone number format: { phone } " )
521
+ return ""
522
+
523
+ # Return formatted phone number with correct country code
524
+ return f"{ country_code } { local_number } "
525
+
472
526
473
527
class BrowserActions :
474
528
"""
0 commit comments