0

I have to create some validation for emails using regex.

I wrote these parts from the validation:

  const regex = {
  whitespace: /^(?!\s+$)/g,
  emailMultipleSeparatedBySemicolon:/^(\s?[^\s,]+@[^\s,]+\.[^\s,]+\s?;)*(\s?[^\s,]+@[^\s,]+\.[^\s,]+)$/g,
};

and I'm using it this way in the code:

 sendTo: Yup.string()
        .max(255, this.props.t("createEmail.error.errorTooLong255"))
        .matches(
          regex.emailMultipleSeparatedBySemicolon,
          this.props.t("createEmail.error.emailMultipleSeparatedBySemicolon")
        )
        .matches(
          regex.whitespace,
          this.props.t("createEmail.error.errorNoWhitespace")
        )
        .required(this.props.t("createEmail.error.required")),

However when I add more than one recipient like this: hNw6B@90.com;test , I don't get the error for invalid email, although the second one test (after the semicolon) is not valid. If I add it this way: hNw6B@90.com; test (with space between the semicolon and test) - it is marked as invalid.

I will be very grateful if you can help me out!

ObiGonz
  • 33
  • 4

0 Answers0