Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isEmpty() not working properly #336

Closed
ghost opened this issue Apr 19, 2017 · 5 comments
Closed

isEmpty() not working properly #336

ghost opened this issue Apr 19, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Apr 19, 2017

Hi, I'm trying to use the isEmpty() method but it always returns error, implying that the validated param is empty, even when it isn't. I've used isEmail() and isLength() methods without any issues. However, Using isEmpty() with the 'validator' npm module directly works properly, so it is an issue in express-validator.

Here's my config:

//
var expressValidator = require('express-validator');
.
.
.
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(expressValidator());
.
.
.
req.checkBody('name', 'Error: name is empty').isEmpty();

There's an open question by someone else in StackOverflow with the same issue: http://stackoverflow.com/questions/43417664/express-validator-isempty-not-working

Please check.

@ghost
Copy link
Author

ghost commented Apr 21, 2017

Just found out that with express-validator, the function to be used is notEmpty().

This should be explicitly displayed in the readme.md to avoid further confussions.

@gustavohenke
Copy link
Member

Feel free to send us a PR to handle this.

@fdorantesm
Copy link

If you send a post variable, this pass if is an empty string ''

@gustavohenke
Copy link
Member

I believe the docs are now a lot better since the v4.0.0 release, and such clarifications will no longer be required.

@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants