how to validate that a field is the same as another?
See original GitHub issueHow can I have rules to validate that the user wrote the same account
and confirmedAccount
?
const inst = yup.object({
account: yup.string().min(7).required(),
confirmedAccount: yup.string().oneOf([yup.ref('account')])
});
inst.validate({ account: '123456', confirmedAccount: '234' }, {
abortEarly: false
}).then(function() {
console.log('ok', arguments);
})
.catch(function(error) {
console.log('failed', error);
});
console.log(inst.cast({ account: '123456', confirmedAccount: '234' }));
Looks like yup.ref
only works for casting data, not for validations?
So, how can I validate it?
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (4 by maintainers)
Top Results From Across the Web
Yup validation with two fields related - Stack Overflow
Validation using value of other form field using Yup test(). · 3. Try, when answering, write code with its description · (val) =>...
Read more >Cross Field Validation - VeeValidate
To reference another field's value, add a @ at the beginning of a param to signal to vee-validate that it should substitute the...
Read more >Laravel validate a field to some value if another ... - Laracasts
Laravel validate a field to some value if another field is different from the same value ? Hello guys,. in my form i...
Read more >How can I ensure that two fields have the same value?
Add an Email field labeled “Email” and another Email field labeled “Confirm Email”. Select the Confirm Email field and find the Show Custom...
Read more >Cross Field Validation Using Angular Reactive Forms
This powerful features let you validate not a single form control but instead you can validate one form control against the value from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FYI: I created this extended validation that looks working:
https://github.com/jquense/yup/issues/49#issuecomment-393100970 has a solution: