How to validate the length of character is equals to 5 using express-validator? How to validate the length of character is equals to 5 using express-validator? express express

How to validate the length of character is equals to 5 using express-validator?


You can use isLength() option of the express-validator to check max and min length of 5:

 req.checkBody('partnerid', 'Partnerid field must be 5 character long ').isLength({ min: 5, max:5 });


You can use matches option of express-validator to check if the partner field only contains alphanumeric and has a length of 5

req.checkBody('partnerid', 'Partnerid field must be 5 character long ').matches(/^[a-zA-Z0-9]{5}$/, "i");