emailValidator function

String? emailValidator(
  1. String? value
)

Validates an email address.

Returns an error message if the email address is invalid or empty. Otherwise, returns null.

Implementation

String? emailValidator(String? value) {
  RegExp regex = RegExp(r'^.+@[a-zA-Z]+\.{1}[a-zA-Z]+(\.{0,1}[a-zA-Z]+)$');
  if (value == null || value.isEmpty) {
    return getCurrentLocalization() == 'id'
        ? 'Kolom tidak boleh kosong'
        : "Field can't be empty";
  } else if (!regex.hasMatch(value)) {
    return getCurrentLocalization() == 'id'
        ? 'Email tidak valid'
        : 'Email not valid';
  }
  return null;
}