最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Yup validation for email to be case insensitive - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 6

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())
      )
发布评论

评论列表(0)

  1. 暂无评论