Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcard object validation supported? #441

Open
JaiPe opened this issue Nov 7, 2021 · 1 comment
Open

Wildcard object validation supported? #441

JaiPe opened this issue Nov 7, 2021 · 1 comment

Comments

@JaiPe
Copy link

JaiPe commented Nov 7, 2021

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 JaiPe changed the title Wildcard object validation Wildcard object validation supported? Nov 7, 2021
@JaiPe
Copy link
Author

JaiPe commented Nov 7, 2021

Possibly related to #416 but not entirely sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant