How to use the isIn function from validator
Find comprehensive JavaScript validator.isIn code examples handpicked from public code repositorys.
98 99 100 101 102 103 104 105 106 107
req.sanitizeBody('secret').trim() req.sanitizeBody('active').toBoolean() req.checkBody(webhookSchema) req.checkBody('labels', 'Invalid label filter (should be a label ID)').optional().isArrayOf(validator.isHexadecimal) req.checkBody('events', 'Invalid event filter (should be create, update or delete)').optional().isArrayOf(item => { return validator.isIn(item, ['create', 'update', 'delete']) }) const validationErrors = req.validationErrors(true) if (validationErrors) { return next(new errors.BadRequest(null, validationErrors))
5
64
0
170 171 172 173 174 175 176 177 178 179
// Checks to be performed in specific situations. // These are not directly exposed to users. var manualChecks = { containsCheck: function(options, x) { x = isString(x) ? x.trim() : ''; check(x, "one of the possible values: " + options.join(","), validator.isIn(x, options)); }, typeCheck: function(fn, x) { var name = fn.name; check(x, "an instance of type " + name, manualTypeChecks[name](x));
2
4
0
145 146 147 148 149 150 151 152 153 154
return validator.isBefore(value); } return true; }, isIn: function(rule, value) { return validator.isIn(value, rule); }, isCreditCard: function(rule, value) { if (rule) { return validator.isCreditCard(value);
0
2
2
+ 5 other calls in file
15 16 17 18 19 20 21 22 23 24
validateUsername(username, password, mobilephone, usertype) { return ( validator.isAlphanumeric(username) && /^((84|0[3|5|7|8|9])+([0-9]{8}))$/.test(mobilephone) && validator.isIn(usertype, [ 1, 2]) && validator.isLength(username, { min: 4, max: 32 }) && validator.isLength(password, { min: 6, max: 32 }) ); }
0
1
0
GitHub: CVELab/Vulnogram
159 160 161 162 163 164 165 166 167 168
.custom((value, { req }) => { // validate username if it is a privileged user // username from unprivileged users will be ignored if ((req.user.priv != 0) || validator.isIn(value, [0, 1, 2])) { return true; } return false; })
0
0
0
GitHub: lasuillard/accompany
23 24 25 26 27 28 29 30 31 32
if ( !((validator.isAlphanumeric(id) && validator.isLength(id, { min: 6, max: 45 })) && validator.isLength(password, { min: 6, max: 100 }) && (validator.isAlphanumeric(nickname) && validator.isLength(nickname, { min: 2, max: 45 })) && validator.isEmail(email) && (validator.isAlphanumeric(username) && validator.isLength(username, { min: 1, max: 16 })) && validator.isIn(gender, ['M', 'F']) && validator.isInt(age, { min: 0, max: 200 })) ) return res.status(400).send({ message: 'Form validation has failed.' }) // preprocess gender = (gender === 'M') ? 1
0
0
0
validator.escape is the most popular function in validator (548 examples)