validCountry static method

PhoneNumberInputValidator validCountry(
  1. List<IsoCode> expectedCountries, {
  2. String? errorText,
  3. bool allowEmpty = true,
})

Implementation

static PhoneNumberInputValidator validCountry(
  /// list of valid country isocode
  List<IsoCode> expectedCountries, {
  /// custom error message
  String? errorText,

  /// determine whether a missing value should be reported as invalid
  bool allowEmpty = true,
}) {
  return (PhoneNumber? valueCandidate) {
    if (valueCandidate != null &&
        (!allowEmpty || valueCandidate.nsn.isNotEmpty) &&
        !expectedCountries.contains(valueCandidate.isoCode)) {
      return errorText ?? 'invalidCountry';
    }
    return null;
  };
}