Zoho Corporation
Zoho Corporation

Reputation: 91

How to validate an array of strings using express validator?

options = ['asdasda', 'asdasdas', 'asdasdasafsaafasfasfasfasfasfasasasasasdas', 'asd'];
req.check('options', 'Option must not exceed 30 characters').isLength({max: 30});

Am trying to validate each string in the array options. Is there any way to do it?

Upvotes: 7

Views: 15944

Answers (1)

gustavohenke
gustavohenke

Reputation: 41440

Yes, you must use wildcards for that.

req.check('options.*').isLength({ max: 30 })

Upvotes: 15

Related Questions