emailValidator static method

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

emailValidator to validate an email address

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

Implementation

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