Reputation: 107
Is there a way to validate LHS Brackets in express-validator for advanced filterings?
Example querystring:
?test[gt]=1
Example validations i tried:
query("test.gt").isAlphanumeric()
query("test[gt]").isAlphanumeric()
seems not work
Upvotes: 1
Views: 1394
Reputation: 4254
https://www.npmjs.com/package/qs is what you need (i guess)
A querystring parsing and stringifying library with some added security.
var qs = require('qs');
var assert = require('assert');
assert.deepEqual(qs.parse('price[gte]=10&price[lte]=100'), {
price: {
gte: 10,
lte: 100
}
});
the example is taken from this blog post: https://www.moesif.com/blog/technical/api-design/REST-API-Design-Filtering-Sorting-and-Pagination/#benefits
Upvotes: 1