isPossibleNumberForTypeWithReason method
Check whether a phone number is a possible number. It provides a more lenient check than isValidNumber in the following sense:
number
the number that needs to be checked
type
the type we are interested in
isPossibleNumberForTypeWithReason returns a ValidationResult object
which indicates whether the number is possible
Implementation
ValidationResult isPossibleNumberForTypeWithReason(
PhoneNumber number, PhoneNumberType type) {
String nationalNumber = getNationalSignificantNumber(number);
int countryCode = number.countryCode;
// Note: For regions that share a country calling code, like NANPA numbers,
// we just use the rules from the default region (US in this case) since the
// getRegionCodeForNumber will not work if the number is possible but not
// valid. There is in fact one country calling code (290) where the possible
// number pattern differs between various regions (Saint Helena and Tristan
// da Cunha), but this is handled by putting all possible lengths for any
// country with this country calling code in the metadata for the default
// region in this case.
if (!_hasValidCountryCallingCode(countryCode)) {
return ValidationResult.invalidCountryCode;
}
String regionCode = getRegionCodeForCountryCode(countryCode);
// Metadata cannot be null because the country calling code is valid.
PhoneMetadata metadata =
_getMetadataForRegionOrCallingCode(countryCode, regionCode)!;
return _testNumberLength(nationalNumber, metadata, type);
}