Reputation: 115
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.
Upvotes: 5
Views: 12747
Reputation: 159
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!')
})
})
Upvotes: 4