isPostalCode function

bool isPostalCode(
  1. String? text,
  2. String locale, {
  3. bool orElse()?,
})

Returns true if text is a valid postal code for locale.

Returns false if text is null. Throws FormatException if locale is not supported and no orElse is provided.

Implementation

bool isPostalCode(String? text, String locale, {bool Function()? orElse}) {
  if (text == null) return false;
  final pattern = postalCodePatterns[locale];
  return pattern != null
      ? pattern.hasMatch(text)
      : orElse != null
      ? orElse()
      : throw FormatException('No postal code pattern for locale: $locale');
}