我正在尝试在我的快速路由器上实现验证,问题是当我通过 {title:""} 时,express-validator 没有抛出错误,但是当我通过 {title:" "} 时它可以工作。
exports.postValidatorCheck = [
check("title", "The title must not we empty").isEmpty(),
check("title", "The Length of the Title should be in greater then 10").isLength({
min: 10,
max: 1500
}),
function(req, res, next) {
let errors = validationResult(req);
console.log(errors);
if (!errors.isEmpty()) {
const firstError = errors.errors.map(err => err.msg)[0];
return res.status(400).json({ error: firstError });
}
next();
}
];
json文件:
{
"title":"",
"body":"This is a new Post"
}
没有错误
JSON 文件
{
"title":" ",
"body":"This is new post"
}
错误如预期。
慕村225694
慕容森
相关分类