@@ -73,6 +73,10 @@ public partial class PhoneNumberUtil
73
73
private static bool IsGeoMobileCountryWithoutMobileAreaCode ( int countryCallingCode )
74
74
=> countryCallingCode is 86 ; // China
75
75
76
+ // Set of country codes that doesn't have national prefix, but it has area codes.
77
+ private static bool IsCountryWithoutNationalPrefixWithAreaCodes ( int countryCallingCode )
78
+ => countryCallingCode is 52 ; // Mexico
79
+
76
80
// Set of country calling codes that have geographically assigned mobile numbers. This may not be
77
81
// complete; we add calling codes case by case, as we find geographical mobile numbers or hear
78
82
// from user reports. Note that countries like the US, where we can't distinguish between
@@ -662,14 +666,18 @@ public int GetLengthOfGeographicalAreaCode(PhoneNumber number)
662
666
var regionCode = GetRegionCodeForNumber ( number ) ;
663
667
if ( ! IsValidRegionCode ( regionCode ) )
664
668
return 0 ;
669
+
670
+ var type = GetNumberType ( number ) ;
671
+ var countryCallingCode = number . CountryCode ;
665
672
var metadata = GetMetadataForRegion ( regionCode ) ;
666
673
// If a country doesn't use a national prefix, and this number doesn't have an Italian leading
667
674
// zero, we assume it is a closed dialling plan with no area codes.
668
- if ( ! metadata . HasNationalPrefix && ! number . HasNumberOfLeadingZeros )
675
+ // Note:this is our general assumption, but there are exceptions which are tracked in
676
+ // COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.
677
+ if ( ! metadata . HasNationalPrefix && ! number . HasNumberOfLeadingZeros &&
678
+ ! IsCountryWithoutNationalPrefixWithAreaCodes ( countryCallingCode ) )
669
679
return 0 ;
670
680
671
- var type = GetNumberType ( number ) ;
672
- var countryCallingCode = number . CountryCode ;
673
681
if ( type == PhoneNumberType . MOBILE
674
682
// Note this is a rough heuristic; it doesn't cover Indonesia well, for example, where area
675
683
// codes are present for some mobile phones but not for others. We have no better way of
0 commit comments