Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在尝试使用express validator进行验证_Express_Express Validator - Fatal编程技术网

正在尝试使用express validator进行验证

正在尝试使用express validator进行验证,express,express-validator,Express,Express Validator,我正在尝试使用确认密码验证我的密码,但它似乎不适用于express validator: 以下是我尝试使用的代码: app.post('/sign-up', body('password').custom((value, { req }) => { if (value !== req.body.confirmPassword) { throw new Error('Password confirmation is incorrect'); } }), (

我正在尝试使用确认密码验证我的密码,但它似乎不适用于express validator:

以下是我尝试使用的代码:

app.post('/sign-up', body('password').custom((value, { req }) => {
    if (value !== req.body.confirmPassword) {
      throw new Error('Password confirmation is incorrect');
    }
  }),
  (req, res) => {
    const user = new User({
      username: req.body.username,
      password: req.body.password,
      confirmPassword: req.body.confirmPassword
    })

    user.save(err => {
    if (err) {
      return next(err);
    };
    res.redirect("/");
  });
});