joi
joi copied to clipboard
Required
I can't get this to work: pass2: Joi.ref('pass').required()
But I can require pass2 with .requiredKeys('pass', 'pass2').
Is this a bug or is there a reason for why the first example does not work while the second does?
Can you put the full object please ?
schema.keys({
pass: Joi.string().regex(/^[\S]{8,20}$/).required(),
pass2: Joi.ref('pass') // I cant add require here.
}).and('pass', 'pass2'); // Therefore I have to to it like this.
schema.keys({
pass: Joi.string().regex(/^[\S]{8,20}$/),
pass2: Joi.ref('pass')
}).requiredKeys('pass', 'pass2') // Or I can do like this.
The 1st one is good, you can also write it this way :
var schema = Joi.object().keys({
pass: Joi.string().regex(/^[\S]{8,20}$/).required(),
pass2: Joi.valid(Joi.ref('pass')).required()
});