2015-04-23 93 views
2

如何檢查密碼和password_confirmation是否一致?hapi route joi驗證密碼確認

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

回答

10

您可以使用Joi.any().valid()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' } } })