Empty string should be valid for a required string parameter
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.
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
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