Node.js express validator validate req.body is not empty
Node.js express validator validate req.body is not empty
有什么优雅的方法可以使用 express-validator 来验证我得到的 req.body 是否为空?
我在这里没有看到任何合适的验证器:https://github.com/chriso/validator.js
而且我不喜欢使用(Object.keys(req.body).length == 0)
我应该构建任何自定义验证器来解决这个问题吗?
谢谢
对于后一个问题 2。如何创建条件验证(至少需要"a","b","c"参数之一)。未经测试,但如下所示的内容应该有效:
var hasRequiredField = Object.keys(req.body).some(function(key) {
return ['a', 'b', 'c'].indexOf(key) >= 0;
});
if(hasRequiredField) {
} else {
}
相关文章:
- Is onfling available for html, html5
- jQuery is not loaded
- reactRedux is not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Jquery - table.row(tr) is undefined
- 不同页面背景的body标记上的角度ng样式
- contentWindow.document.body is null
- Tomcat websocket is not working
- noty.js is returning undefined
- $routeParams is undefined
- 在jQuery中使用$('body').html('')意味着什么
- NodeJS Multer is not working
- React, Webpack: bundle.js is not generated
- jQuery is not defined - WordPress footer.php
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- 如果在iframe中查看页面,如何在Wordpress中添加body类
- Is it better to use <body onEvent=""> or <
- document.body.addEventListener is not working
- Node.js express validator validate req.body is not empty
- JavaScript - req.body.username is undefined