Created
December 5, 2016 10:18
-
-
Save jbutko/ce6a109b3feef2a8238cb8216731d3f0 to your computer and use it in GitHub Desktop.
Custom express validators via express-validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/37339479/express-validator-to-validate-paramenter-which-is-an-array#answer-37342458 | |
var expressValidator = require('express-validator'); | |
var validator = require('validator'); | |
app.use(expressValidator({ | |
customValidators: { | |
isArray: function(value) { | |
return Array.isArray(value); | |
}, | |
notEmpty: function(array) { | |
return array.length > 0; | |
} | |
gte: function(param, num) { | |
return param >= num; | |
} | |
} | |
})); | |
req.checkBody('category', 'category cannot be empty').isArray().notEmpty(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment