Last active
September 30, 2023 17:59
-
-
Save JoaoCnh/4101c0c4896c07d2357aed4aeab33aae to your computer and use it in GitHub Desktop.
Yup conditional validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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