validate icon indicating copy to clipboard operation
validate copied to clipboard

Empty string should be valid for a required string parameter

Open jmwilkinson opened this issue 8 years ago • 2 comments

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.

jmwilkinson avatar Mar 30 '18 20:03 jmwilkinson

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

eivindfjeldstad avatar Mar 30 '18 23:03 eivindfjeldstad

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:

https://github.com/eivindfjeldstad/validate/issues/118

ericmorand avatar Apr 23 '21 21:04 ericmorand