isValidShortNumber method

bool isValidShortNumber(
  1. PhoneNumber number
)

Tests whether a short number matches a valid pattern. If a country calling code is shared by multiple regions, this returns true if it's valid in any of them. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. See isValidShortNumberForRegion(PhoneNumber, String) for details.

number the short number for which we want to test the validity returns whether the short number matches a valid pattern

Implementation

bool isValidShortNumber(PhoneNumber number) {
  List<String> regionCodes =
      _getRegionCodesForCountryCode(number.countryCode);
  String? regionCode =
      _getRegionCodeForShortNumberFromRegionList(number, regionCodes);
  if (regionCodes.length > 1 && regionCode != null) {
    // If a matching region had been found for the phone number from among two or more regions,
    // then we have already implicitly verified its validity for that region.
    return true;
  }
  return isValidShortNumberForRegion(number, regionCode);
}