Skip to content

Instantly share code, notes, and snippets.

@JoaoCnh
Last active September 30, 2023 17:59
Show Gist options
  • Save JoaoCnh/4101c0c4896c07d2357aed4aeab33aae to your computer and use it in GitHub Desktop.
Save JoaoCnh/4101c0c4896c07d2357aed4aeab33aae to your computer and use it in GitHub Desktop.
Yup conditional validation
Yup.object().shape({
email: Yup.string().email('Invalid email address').required('Email is required!'),
username: Yup.string().required('This man needs a username').when('email', (email, schema) => {
if (email === 'foobar@example.com') { return schema.min(10); }
return schema;
}),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment