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"),
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())
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With