isPossibleNumberWithReason method

ValidationResult isPossibleNumberWithReason(
  1. PhoneNumber number
)

Check whether a phone number is a possible number. It provides a more lenient check than isValidNumber in the following sense:

  1. It only checks the length of phone numbers. In particular, it doesn't check starting digits of the number.
  2. It doesn't attempt to figure out the type of the number, but uses general rules which applies to all types of phone numbers in a region. Therefore, it is much faster than isValidNumber.
  3. For some numbers (particularly fixed-line), many regions have the concept of area code, which together with subscriber number constitute the national significant number. It is sometimes okay to dial only the subscriber number when dialing in the same area. This function will return [isPossibleLocalOnly] if the subscriber-number-only version is passed in. On the other hand, because isValidNumber validates using information on both starting digits (for fixed line numbers, that would most likely be area codes) and length (obviously includes the length of area codes for fixed line numbers), it will return false for the subscriber-number-only version.

There is a known issue with this method: if a number is possible only in a certain region among several regions that share the same country calling code, this method will consider only the "main" region. For example, +1310xxxx are valid numbers in Canada. However, they are not possible in the US. As a result, this method will return [isPossibleLocalOnly] for +1310xxxx.

@param number the number that needs to be checked @return a ValidationResult object which indicates whether the number is possible.

Implementation

ValidationResult isPossibleNumberWithReason(PhoneNumber number) {
  return isPossibleNumberForTypeWithReason(number, PhoneNumberType.unknown);
}