validatorjs
validatorjs copied to clipboard
Wildcard object validation supported?
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 👋
Possibly related to #416 but not entirely sure.