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

Empty string should be valid for a required string parameter #39

Open
jmwilkinson opened this issue Mar 30, 2018 · 2 comments
Open

Empty string should be valid for a required string parameter #39

jmwilkinson opened this issue Mar 30, 2018 · 2 comments

Comments

@jmwilkinson
Copy link

Currently the code:

  required(value, ctx, required) {
    if (required === false) return true;
    return value != null && value !== '';
  },

causes validation to fail on an empty string. However, an empty string may very well be a valid value on for a required field. This check causes false failures. There should be a separate parameter to require a value not be empty if that intent is required.

@eivindfjeldstad
Copy link
Owner

eivindfjeldstad commented Mar 30, 2018

See #32. In the past, this library has been geared towards validating request bodies etc., where it makes sense to consider an empty string invalid. This will probably be changed in the next major version

@ericmorand
Copy link

ericmorand commented Apr 23, 2021

For those that needs empty string to be considered as a valid required value, I published a fork that implement that behavior:

https://www.npmjs.com/package/@nightlycommit/validate

It also fixes the following issue:

#118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants