Hapi route joi password confirmation confirmation
How can I check that the password and password_confirmation are the same?
var Joi = require('joi'),
S = Joi.string().required().min(3).max(15);
exports.create = {
payload: {
username: S,
email: Joi.string().email(),
password: S,
password_confirmation: S
}
}
You can use Joi.any().valid()
with Joi.ref()
:
password: Joi.string().min(3).max(15).required(),
password_confirmation: Joi.any().valid(Joi.ref('password')).required().options({ language: { any: { allowOnly: 'must match password' } } })
I have to resurrect this thread because I tried the code above and the validation error worked even though the password and password confirmation match.
I spent several hours trying several approaches but still no luck, the check still runs, e.g .:
password: Joi.string (). min (5) .required (), password Confirmation: Joi.ref ("password")
Here is my state facility:
data: {…} email: "" password: "12345" passwordConfirmation: "12345" username: "" error: {…} passwordConfirmation: "\" passwordConfirmation \ "must be one of [ref: password]"
I have other validations on this form and they are working fine.