validatePhoneNumberByContry static method

bool validatePhoneNumberByContry(
  1. String phoneNumber,
  2. Country country
)

Validate a phone number based on the country

Implementation

static bool validatePhoneNumberByContry(String phoneNumber, Country country) {
  int length = phoneNumber.length;
  bool lengthValid =
      length >= country.phoneMinLength && length <= country.phoneMaxLength;
  bool startingDigitsValid = country.startingDigits.isEmpty ||
      country.startingDigits.any((digits) => phoneNumber.startsWith(digits));
  return lengthValid && startingDigitsValid;
}