emailValidator static method
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;
}