Hello!
I’m struggling a little bit with Joi validation - specifically how to validate the password confirmation field.
In the documentation example schema it gives the password confirmation as:
repeat_password: Joi.ref('password'),
Yet that only works if the referenced property, password, passes its validation.
Is there any way to have repeat_password (or in my case confirmPassword) be required()
and be equal to password
?
I’ve tried the following from stackoverflow, with no luck:
// confirmPassword: Joi.any().valid(Joi.ref('password')).required()
// confirmPassword: Joi.string().required().equal(Joi.ref('password'))
// confirmPassword: Joi.string().required().valid(Joi.ref('password'))
// confirmPassword: Joi.any().valid(Joi.ref('password')).required().options({ language: { any: { allowOnly: 'must match password' } } })
Codepen example here (type a password to see the validation actually work)
I’m also struggling to get the messages
function to work. It just straight up says it isn’t a function when I try to chain it.
It’s probably just me, but is Joi… a bit rubbish? It’s making me really like express-validator
right now, and that’s a massive achievement!
Would really appreciate some help if anyone has had difficulties with this before!
Thanks!
Nick