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"),
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"),
Share
Improve this question
asked May 4, 2020 at 9:34
khalil elloumikhalil elloumi
972 silver badges10 bronze badges
1 Answer
Reset to default 6You 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())
)