How do I add custom validation to validate if the object has two properties of same value? #966
Replies: 1 comment
-
import * as v from 'valibot';
const RegisterSchema = v.pipe(
v.object({
email: v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email address is badly formatted.')
),
password1: v.pipe(
v.string(),
v.nonEmpty('Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.')
),
password2: v.string(),
}),
v.forward(
v.partialCheck(
[['password1'], ['password2']],
(input) => input.password1 === input.password2,
'The two passwords do not match.'
),
['password2']
)
); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
fabian-hiller
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, there!!! I'm validating signup data where user should pass an object containing two fields:
How do I check if the
password
andpasswordconfirm
contains equal value? Thanks.Beta Was this translation helpful? Give feedback.
All reactions