Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yup validation for email to be case insensitive

I have an Array of emails and have an email text field in which user inputs email however I need the input to be different from any of these emails in the array , I used Yup.notOneOf but I still lack the case insensitivity so I need the email to be different. I already tried creating a lowerCase or Uppercase array for emails but didn't solve my issue if the user writes in alternance

email: Yup.string()
      .email("Invalid Email.")
      .notOneOf(lowerEmails, "Email already exists.")
      .notOneOf(upperEmails,"Email already exists")
      .required("Required"),
like image 694
khalil elloumi Avatar asked Nov 04 '25 05:11

khalil elloumi


1 Answers

You can use .test to do whatever you like. In your case, something like this should do it:

email: Yup.string()
      .email("Invalid Email.")
      .required("Required"),
      .test(
         'existsCheck',
         'Email already exists',
         value => !lowerEmails.includes(value.toLowerCase())
      )
like image 154
Will Jenkins Avatar answered Nov 06 '25 20:11

Will Jenkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!