Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
Yup validation not work when use not(!) in matches function

I have a project with React and next js. I use formik for handling my forms and Yup for validations I have an input and I want perform some validations on it.

  1. this field must be required so if user don't enter any information I show this message => Required
  2. this field should not contain any numbers otherwise I Show this message => Wrongggg
  3. this field must only contain Persian characters otherwise I Show this message => only Persian chars this is my schema

 Yup.string()
            .required("Requiredddd")
            .matches(!/\d/, 'Wrongggg'),
            .matches(/^[\u0600-\u06FF\s]+$/, 'Only persian chars')

But in this case condition number 2 always Considered wrong.i think (!/\d/) is wrong but I haven't any idea how can use matches function Negatively

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

According to yup you can use .matches using this shape: string.matches(regex: Regex, message?: string | function): Schema. If you want to validate that the string doesn't contain numbers, instead of using (!/\d/) you should use /\D+$/.

 Yup.string()
            .required("Requiredddd")
            .matches(/\D+$/, 'Wrongggg')
            .matches(/^[\u0600-\u06FF\s]+$/, 'Only persian chars')

See working example

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!