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

How can I validate that at least one of two or more optional parameters is present #47

Open
gnl1 opened this issue Mar 18, 2020 · 0 comments

Comments

@gnl1
Copy link

gnl1 commented Mar 18, 2020

Hi,

I would like to know if there is a way to validate a json payload in such a way that it checks if there exists only one of two or more optional keys as well as validate its contents? i.e. in the following payloads the first two should fail since the first one does not include "telephone1" key, the second one should fail since it includes both "telephone1" and "telephone2" keys, the third should fail because has less characters than 8 as well as it contains alpha characters and the fourth one should pass since it includes a single key i.e "telephone2" and it consists of only numbers and has a length of 8

Payload 1: (Should fail)
{
"name": "george"
}

Payload 2: (Should fail)
{
"name": "george",
"telephone1": "12345678",
"telephone2": "87654321"
}

Payload 3: (Should fail cause less than 8 characters and it contains alpha characters)
{
"name": "george",
"telephone2": "ABC123"
}

Payload 4: (Should pass)
{
"name": "george",
"telephone2": "87654321"
}

Thanks.

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