Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do multiple validations for a single value in yup?

Using joi on the server side, I can do multiple validations like id: [joi.string().email(), joi.string().min(10)].

How can we do this on frontend using formik and yup? I went through the docs and still no success.

like image 962
abhishek Avatar asked Oct 17 '22 06:10

abhishek


1 Answers

You should try Yup like this.

const formikEnhancer = withFormik({
      validationSchema: Yup.object().shape({
        name: Yup.string().strict(true).lowercase('Name must be lowercase').matches(/^\S+$/, 'Name must not contain spaces').matches(/^(?:(?!\.).)*$\r?\n?/, 'Name must not contain period').max(10, 'Maximum of 10 characters')
          .required('Name is required!'),
         email: Yup.string().strict(true).lowercase('Email must be lowercase').required('Email is required!')
      })
    })
like image 66
Vikram Mevasiya Avatar answered Oct 20 '22 15:10

Vikram Mevasiya