2015-08-26 75 views
0

尝试使用快速验证验证某些表单输入。 一切工作正常,但无法弄清楚我如何检查相同的密码。快速验证密码验证(等于密码)

// form validation 
req.checkBody('name', 'Name is required').notEmpty(); 
req.checkBody('email', 'Email is required').notEmpty(); 
req.checkBody('email', 'Email not valid').isEmail(); 
req.checkBody('username', 'username is required').notEmpty(); 
req.checkBody('password', 'password is required').notEmpty(); 
//req.checkbody('password2', 'Password do not match').equals(req.body.password); 

// check for errors 
var errors = req.validationErrors(); 
if(errors) { 
    res.render('register', { 
    errors: errors, 
    name: name, 
    email: email, 
    username: username, 
    password: password, 
    password2: password2 
}); 

在这里,我得到这个: enter image description here

正如你所看到的,这工作得很好。 但使用后:

req.checkbody('password2', 'Password do not match').equals(req.body.password); 

enter image description here

它不会工作,因为我谷歌解决这个有寿工作! 有人熟悉这个问题? 顺便说一句,刚开始学习node.js,并由疯狂englisch抱歉。 如果有人需要更多的信息,我很乐意提供。 谢谢

ps。 已经尝试过:

req.assent('password2', 'Password do not match').equals(req.body.password); 
+5

'checkbody'缺少资本2 ... – robertklep

回答

0

似乎一切就OK了可能是你忘了检查:

req.checkBody('password', 'password is required').notEmpty(); 
req.checkBody('password2', 'password2 is required').notEmpty(); 
req.checkbody('password2', 'Password do not match').equals(req.body.password); 
+1

的OP有问题的代码示例这些行。 .. – marekful

+0

没有他忘记第二次检查,没有检查密码2空 – trquoccuong

+2

哎哟,这有点尴尬。这是首都B:|。有什么不对吗? ; p –