Here is my code. I want to check that name is alphabetic and have more than 2 characters, but this code doesn't generate any error.
const {body, validationResult} = require('express-validator');
function nameValidation(req, res, next){
body('name').trim().isLength({ min: 1 }).withMessage('Name empty.')
.isLength({ min: 3 }).withMessage('Name must contain min 2 letters.')
.isAlpha().withMessage('Name must be alphabet letters.');
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
next();
}