isValidNumber method

bool isValidNumber(
  1. PhoneNumber number
)

Tests whether a phone number matches a valid pattern. Note this doesn't verify the number is actually in use, which is impossible to tell by just looking at a number itself. It only verifies whether the parsed, canonicalised number is valid: not whether a particular series of digits entered by the user is diallable from the region provided when parsing. For example, the number +41 (0) 78 927 2696 can be parsed into a number with country code '41' and national significant number '789272696'. This is valid, while the original string is not diallable.

number the phone number that we want to validate. isValidNumber returns a boolean that indicates whether the number is of a valid pattern.

Implementation

bool isValidNumber(PhoneNumber number) {
  String? regionCode = getRegionCodeForNumber(number);
  return isValidNumberForRegion(number, regionCode);
}