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

add validateIfExists method #8

Closed
mocheng opened this issue Jan 14, 2015 · 1 comment
Closed

add validateIfExists method #8

mocheng opened this issue Jan 14, 2015 · 1 comment

Comments

@mocheng
Copy link
Collaborator

mocheng commented Jan 14, 2015

In my practical programming context, there are such kind of code

function some_action(req, res) {
   var validr = new Validr(req.body);
   if (req.body.phone_num) { 
       validr.validate('phone_num', 'phone number  should be valid').isNumeric();
   }

}

Some arguments, suck as phone_num in above code is optional. So, we only need to validate it if it exists. However, having if statement to check its existence introduce increased cyclomatic complexity.

If there an validateIfExists function to do validation only given field exists or empty. That would be great.

@mocheng
Copy link
Collaborator Author

mocheng commented Jan 14, 2015

Or else, we can have add method ``ignoreEmpty&ignoreUndefined`property to `validr` .

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