validatorjs icon indicating copy to clipboard operation
validatorjs copied to clipboard

Wildcard object validation supported?

Open JaiPe opened this issue 3 years ago • 1 comments

Hi there.

Using v3.22.1 and it seems we can't validate the values of unknown object keys? e.g.

Input:

{
  "yourFriendsNamesAndAges": {
    "fred": "invalid-must-be-a-number",
    "simon": 55
  }
}

Validator:

{
  "yourFriendsNamesAndAges.*": "number"
}

Is this a supported feature, but my usage is wrong? Or is that currently not supported?

Use-case: Validating user-defined options when users are allowed to specify their own keys (arbitrary / unknown during buildtime), but the value must meet a certain format

const validate = new Validator({
  yourFriendsNamesAndAges: {
    fred: 'invalid-must-be-a-number',
    simon: 55
  }
}, {
  'yourFriendsNamesAndAges.*': 'number'
})

console.log(validate.errors.first()) // false .... would expect true, for 'fred'?

Thanks for your help 👋

JaiPe avatar Nov 07 '21 10:11 JaiPe

Possibly related to #416 but not entirely sure.

JaiPe avatar Nov 07 '21 10:11 JaiPe