【问题标题】:express-validation password validation (equal passwords)express-validation 密码验证(相等密码)
【发布时间】:2015-08-26 13:56:47
【问题描述】:

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

// 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
});

这里我明白了:

如您所见,这很好用。 但使用后:

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

它不起作用,当我在谷歌周围搜索时,它必须起作用! 有人熟悉这个问题吗? 顺便说一句,刚开始学习 node.js,并为 mad englisch 感到抱歉。 如果有人需要更多信息,我很乐意提供。 谢谢

ps。 已经试过了:

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

【问题讨论】:

  • checkbody 缺少大写字母 B...

标签: node.js validation express


【解决方案1】:

似乎一切正常,可能是您忘记了支票:

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);

【讨论】:

  • 不,他忘记了第二次检查,没有检查密码2为空
  • 天哪,这有点尴尬。它是大写 B :|。我是怎么了? ;p
  • 哦,有时我遇到了区分大小写的问题
猜你喜欢
  • 1970-01-01
  • 2012-09-14
  • 1970-01-01
  • 1970-01-01
  • 2021-02-28
  • 1970-01-01
  • 2011-01-24
  • 1970-01-01
相关资源
最近更新 更多