question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add example how to validate than one field matches another

See original GitHub issue

I cannot find any example or appropriate function in the API how to make sure that one field has the same value as another (string in my case). Use case matching password and passwordRepeat fields.

I’m thinking I need to use ref, but I’m not sure how exactly. I was thinking of matches (but can I pass exact field value there) or oneOf.

yup.object().shape({
  newPassword: yup.string().min(5).required().label('New password'),
  reNewPassword: yup.string(),
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

76reactions
TimonVScommented, May 30, 2018

The example that @jquense posted isn’t working for me. This is what worked for me:

password: yup.string().required('Password is required'),
confirmPassword: yup.string().oneOf([yup.ref('password'), null], "Passwords don't match").required('Confirm Password is required'),

I got it from https://github.com/jquense/yup/issues/164

13reactions
yantakuscommented, Nov 10, 2016

@chodorowicz This can be just:

string().oneOf([this.state.model.password], "Passwords don't match")
Read more comments on GitHub >

github_iconTop Results From Across the Web

java - How can I validate two or more fields in combination?
This String, we will add to a set by using add() of set which will return false if duplicate comes up. Based on...
Read more >
Restrict data input by using validation rules - Microsoft Support
On the Fields tab, in the Field Validation group, click Validation, and then click Record Validation Message. Enter an appropriate message. For example,...
Read more >
REGEX - How to match and search any pattern or validate ...
This video covers the most important uses of regex: - regex match (used to check if a string matches a specific regex rule)...
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 >
Excel Data Validation using regular expressions (Regex)
To be able to validate cell input using regular expressions, you need to create a custom Regex function first. Another complication is that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found