isEmailValid method

bool isEmailValid(
  1. String data
)

Checks if the provided data is a valid email address.

Returns true if data is not a valid email address, otherwise returns false.

Example:

bool isValid = isEmailValid('example@email.com'); // Returns false
bool notValid = isEmailValid('example@'); // Returns true

Note: This function validates the format of the email address but does not verify its existence or validity.

Example:

bool isValid = isEmailValid('example@'); // Returns true (invalid format)

Implementation

bool isEmailValid(String data) {
  var expCheck = RegExp(
      r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+");
  if (!expCheck.hasMatch(data)) {
    return true;
  }
  return false;
}