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

notEmpty() not working #476

Closed
dhpradeep opened this issue Dec 1, 2017 · 11 comments
Closed

notEmpty() not working #476

dhpradeep opened this issue Dec 1, 2017 · 11 comments

Comments

@dhpradeep
Copy link

Hi , i'm using latest version of express-validator,
and there is nothing about notEmpty in readme.md .
when i use it shows this message
check('topic', 'this is not be empty').notEmpty(),

TypeError: check(...).notEmpty is not a function

so how can i use ?

@0bs3n
Copy link

0bs3n commented May 16, 2018

I see that you closed this issues the same day you posted it, but I am now facing the same issue as you. It appears that "notEmpty()" is no longer provided by validator.js as a validator, but is there an alternative? I simply want to make sure that an input on a form is not empty. I realize this can be done with the "required" html attribute, but I want to know if there is a standard way to do it via express-validator, so I can keep all my validation in one place.

@gustavohenke
Copy link
Member

Hi @Ethan-ks,
Looks like this issue fell off my radar.

"notEmpty()" is no longer provided by validator.js as a validator

It was never a validator.js validator. Actually, it was an express-validator validator in the legacy API (in fact, it still is).

is there an alternative?

Yes, with the check API you can use check('something').not().isEmpty() for now.

I acknowledge this was way too popular in previous versions of express-validator, so I'm willing to bring it back.

@0bs3n
Copy link

0bs3n commented May 17, 2018

I think that check('thing').not().isEmpty() is actually plenty straightforward, the problem lies in the check().not() method not being clearly documented. I looked through the check API page as well as the list of validators withing the validator.js documentation, and didn't see any mention of it. If I'm simply missing it, please point it out to me, otherwise, I think mentioning the existance of the method would avoid future issues like this. Thanks.

@gustavohenke
Copy link
Member

I looked through the check API page as well as the list of validators withing the validator.js documentation, and didn't see any mention of it

Again, not a validator.js thing.

The check API returns a Validation Chain, which in turn contains all of validator.js validators + a few other methods (these being documented there).

Do you know of any way we could improve the docs to make these more prominent?

@maryamkhidir
Copy link

Thanks @gustavohenke for the solution. I was facing a similar bug to @dhpradeep and I was able to fix it with the solution you provided. Thanks man

@shanutthankachan
Copy link

use, check('lastName').not().isEmpty().withMessage('The Last name is required')

@jakazzy
Copy link

jakazzy commented Jan 3, 2019

Thanks @gustavohenke I faced this issue. Followed your solution and it worked. Big ups!

@jaguardev
Copy link

jaguardev commented Jul 15, 2019

using not().isEmpty() works for imperative style great
what about schema validation?
let's say how to validate not empty and not a number?

checkSchema({
    id: {
      not: true,
      isEmpty: true,
      not: true, // like this? :)
      isInt: true, // -- like this, but not a number
    }
})

@gustavohenke
Copy link
Member

Hey @jaguardev,
You would do it like this:

checkSchema({
	id: {
		isEmpty: {
			negated: true,
		}
	}
})

@gustavohenke
Copy link
Member

Shipped in v6.3.0!

@lock
Copy link

lock bot commented Jan 24, 2020

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 Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants