Javascript 快速验证程序检查(';密码确认';)
我一直收到以下错误:Javascript 快速验证程序检查(';密码确认';),javascript,express,validation,Javascript,Express,Validation,我一直收到以下错误: Result { formatter: [Function: formatter], errors: [ { value: '12345', msg: 'Invalid value', param: 'passwordConfirmation', location: 'body' } ] } requirePassword: check('password') .trim() .i
Result {
formatter: [Function: formatter],
errors: [
{
value: '12345',
msg: 'Invalid value',
param: 'passwordConfirmation',
location: 'body'
}
]
}
requirePassword: check('password')
.trim()
.isLength({ min: 4, max: 20})
.withMessage('Must be 4 to 20 characters'),
requirePasswordConfirmation: check('passwordConfirmation')
.trim()
.isLength({ min: 4, max: 20 })
.withMessage('Must be 4 to 20 characters')
.custom((passwordConfirmation, { req }) => {
if(passwordConfirmation !== req.body.password){
throw new Error('Passwords must match')
}
})
使用以下代码:
Result {
formatter: [Function: formatter],
errors: [
{
value: '12345',
msg: 'Invalid value',
param: 'passwordConfirmation',
location: 'body'
}
]
}
requirePassword: check('password')
.trim()
.isLength({ min: 4, max: 20})
.withMessage('Must be 4 to 20 characters'),
requirePasswordConfirmation: check('passwordConfirmation')
.trim()
.isLength({ min: 4, max: 20 })
.withMessage('Must be 4 to 20 characters')
.custom((passwordConfirmation, { req }) => {
if(passwordConfirmation !== req.body.password){
throw new Error('Passwords must match')
}
})
我尝试了许多不同的密码,但密码确认总是错误的,而不是密码。我不明白为什么在custom()的回调结束时出现无效值错误返回true