validateEmailAddress function

Either<ValueObjectFailure<String>, String> validateEmailAddress(
  1. String input
)

validateEmailAddress checks for the validity of the provided input

Implementation

Either<ValueObjectFailure<String>, String> validateEmailAddress(String input) {
  final RegExp emailRegex = RegExp(
      r"""^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+""");

  if (emailRegex.hasMatch(input)) {
    return right(input);
  } else {
    return left(
        ValueObjectFailure<String>.invalidEmailAddress(failedValue: input));
  }
}