validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Required assert should only check if value is defined

Open fixe opened this issue 9 years ago • 1 comments

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.

fixe avatar Mar 01 '15 15:03 fixe

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

cuteboi avatar Aug 13 '15 00:08 cuteboi