call method

  1. @override
String? call(
  1. String attribute,
  2. String value
)
override

Validates whether a value is a valid email address.

This method checks if the input value matches a valid email address pattern using a regular expression. If the value does not match the pattern, an error message is generated using the buildMessage method.

Parameters:

  • attribute: The identifier of the form attribute being validated.
  • value: The value to be validated.

Returns: A validation error message if the value does not represent a valid email address, or null if the value is a valid email address.

Implementation

@override
String? call(String attribute, String value) {
  if (value.isNotEmpty) {
    RegExp exp = RegExp(
        r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$",
        caseSensitive: false);
    if (!exp.hasMatch(value)) {
      return buildMessage(attribute, value);
    }
  }
  return null;
}