hapi route joi validation of password confirmation

不问归期 提交于 2019-12-10 03:59:37

问题


How do I check that 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
   }
}

回答1:


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' } } })


来源:https://stackoverflow.com/questions/29827082/hapi-route-joi-validation-of-password-confirmation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!