Skip to content

Instantly share code, notes, and snippets.

@pratikagashe
Created May 15, 2020 12:45
Show Gist options
  • Save pratikagashe/07ea5b60461e41f65bf128a2919aee33 to your computer and use it in GitHub Desktop.
Save pratikagashe/07ea5b60461e41f65bf128a2919aee33 to your computer and use it in GitHub Desktop.
Formik validate vs yup validation schema
// With Yup validationSchema
validationSchema={Yup.object().shape({
email: Yup.string()
.email()
.required('Enter valid email-id'),
})}
// With Formik Validate
validate={values => {
const errors = {};
if (!values.email) {
errors.email = 'Required';
} else if (
!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(values.email)
) {
errors.email = 'Invalid email address';
}
return errors;
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment