validateEmails method

String? validateEmails(
  1. String? value
)

Implementation

String? validateEmails(String? value) {
  Pattern pattern =
      r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
  RegExp regex = RegExp(pattern.toString());
  var emails = value!.split(",");
  for (String email in emails) {
    if (!regex.hasMatch(email.trim())) {
      return "$email is not a valid email address";
    }
  }
  return null;
}