isValidShortNumberForRegion method

bool isValidShortNumberForRegion(
  1. PhoneNumber number,
  2. String? regionDialingFrom
)

Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself.

number the short number for which we want to test the validity regionDialingFrom the region from which the number is dialed returns whether the short number matches a valid pattern

Implementation

bool isValidShortNumberForRegion(
    PhoneNumber number, String? regionDialingFrom) {
  if (!_regionDialingFromMatchesNumber(number, regionDialingFrom)) {
    return false;
  }

  PhoneMetadata? phoneMetadata =
      _getShortNumberMetadataForRegion(regionDialingFrom!);
  if (phoneMetadata == null) {
    return false;
  }

  String shortNumber = _getNationalSignificantNumber(number);
  PhoneNumberDesc generalDesc = phoneMetadata.generalDesc;
  if (!_matchesPossibleNumberAndNationalNumber(shortNumber, generalDesc)) {
    return false;
  }

  PhoneNumberDesc shortNumberDesc = phoneMetadata.shortCode;
  return _matchesPossibleNumberAndNationalNumber(
      shortNumber, shortNumberDesc);
}