postalAddressValidator static method

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

postalAddressValidator to validate postal address

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

Implementation

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