guillaumepotier / validator.js

Powerful objects and strings validation in javascript for Node and the browser
http://validatorjs.org
MIT License
255 stars 39 forks source link

Required assert should only check if value is defined #29

Open fixe opened 9 years ago

fixe commented 9 years ago

I think that the assert is doing more than it should. This shouldn't be invalid:

validator.validate({
  foobar: [],
  foobiz: ''
}, {
  foobar: [
    new Assert().Required(),
    new Assert().InstanceOf(Array)
  ],
  foobiz: [
    new Assert().Required()
  ]
});

@guillaumepotier WDYT? Currently I'm overriding the assert but if you agree I can create a PR.

cuteboi commented 9 years ago

Those look quite valid, if you need to specify a length, maybe you should check Length() too, which works for strings and arrays.