onValidate method

  1. @override
String? onValidate(
  1. String? value,
  2. String validationMessage
)
override

onValidate is used to validate the given input by the user.

Implementation

@override
String? onValidate(
  String? value,
  String validationMessage,
) {
  if (mandatory) {
    if (value == null || value.isEmpty) {
      return validationMessage;
    }

    if (!RegExp(
      r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+",
    ).hasMatch(value)) {
      return validationMessage;
    }
  }

  return null;
}