No errors with express-validator isEmpty

Arun kumar picture Arun kumar · Jun 8, 2018 · Viewed 11.9k times · Source

I am using express-validator 5.2.0 in a expressjs app. I implemented the validaiton on a form data. But it does not capture the errors and gives empty errors object. When validation runs it shows the "no error" when I submit the empty form. It should follow the error path and should display the error.

Answer

gustavohenke picture gustavohenke · Jun 12, 2018

check('firstName', 'First Name is required').isEmpty() is enforcing firstName to be empty.
You will want to change that last part to .not().isEmpty(), so that you invert the isEmpty validator.

Might also be of your interest: https://github.com/express-validator/express-validator/issues/476