Yup is a JavaScript object schema validator and object parser.
To check if the values of two fields are same or not using Yup, you can do:
Yup.object().shape({
field1: Yup.string()
.required('Required'),
field2: Yup.string()
.oneOf([Yup.ref('field1'), null], "Does not match with field1!")
.required('Required')
});
For example, if you are validating password and repeat password it will be like:
Yup.object().shape({
password: Yup.string()
.required('Required'),
confirmPassword: Yup.string()
.oneOf([Yup.ref('password'), null], "Passwords don't match!")
.required('Required')
});
0 Comments