postalCodeValidator static method

String? postalCodeValidator(
  1. String? value, [
  2. String? errorMessage
])

postalCodeValidator to validate postal code

validator: (value) => SimpleValidations.postalCodeValidator(value, [errorMessage]),

Implementation

static String? postalCodeValidator(String? value, [String? errorMessage]) {
  RegExp regex = CustomRegEx.postalCodeRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid postal code';
  }
  return null;
}