ansman / validate.js

A declarative validation library written javascript
https://validatejs.org
MIT License
2.63k stars 336 forks source link

Unclear how to validate an optional field #150

Closed theogravity closed 7 years ago

theogravity commented 8 years ago

What's the proper way to validate an optional field?

For example, I have a field called cvv that's optional, but if filled in should be a min length of 3 with a max of 4 chars

ansman commented 8 years ago

All fields are optional unless you use the presence spec. You can also use a conditional constraint if you need CVV based on another attribute: http://validatejs.org/#constraints (see the example, creditCardZip to be specific)

sckogi commented 7 years ago

@theogravity Look here: https://github.com/ansman/validate.js/issues/99#issuecomment-239890891