Good examples for password and repeat password validation #13133
Unanswered
binarykitchen
asked this question in
Q&A
Replies: 2 comments
-
|
One option is to use Zod. See here for the RHF docs. You can define a schema with a password field and a confirm password field. When either changes, the validation is re-run and the confirm password error will be re-triggered. Here's an example schema. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks @BrendanC23 I see. I'm just reluctant to use Zod or Yup for a small form as it feels like an overhead. Surprised react-hook-form alone cannot do this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello folks,
I'm stuck with a problem where a user enters the repeat password first and only then enters the password.
How can I trigger to revalidate the repeat password after the user has entered the first password?
If you look at this example
https://github.com/react-hook-form/react-hook-form/blob/master/examples/V7/getValuesCompareFields.tsx
It has one bug: when the new password has changed, it does not re-trigger the validation for the repeat password.
And putting the
triggerfunction inside a validation function will lead to a deadlock, it will loop forever and freezes the browser.Suggestions very welcome. Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions