'required' rule validates properly only if a property is not present. #32

MKxDev opened this Issue Oct 14, 2012 · 7 comments


None yet

4 participants


'required' fails to validate only if the validated property is not present in the object, not when it's empty. Please see the following jsfiddle for an example (inspect in console): http://jsfiddle.net/CAc94/1/

EDIT: Sorry, jsfiddle might now validate properly, since I think I fixed it in my forked version.


That is intentional. If you want to check against strings being empty, you should use minLength: 1.

@pksunkara pksunkara closed this Oct 29, 2012

pksunkara, did you delete my comment about the design decision? Why?


what? No. I dont do that stuff.

Actually, I did not receive your comment at all in my notifications. You sure you submitted?


Hey. I was sure until I read your comment. Must've gotten lost in the interwebs.

I wanted to comment that from design perspective, it'd be helpful to have 'required' validate the presence of a value, not the property. Additionally, I'd have a flag that would then force it to validate the presence of a property. Just my $.02


@indexzero Can you decide on this?

a decoupled application framework member

See: http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7

5.7.  required

   This attribute indicates if the instance must have a value, and not
   be undefined.  This is false by default, making the instance

The empty string is not undefined. So this would break JSONSchema compatibility which is a primary goal.

@seangarner seangarner added a commit to seangarner/revalidator that referenced this issue Feb 5, 2014
@seangarner seangarner revert #53 to fix empty string usecase
#53 changed behaviour of `required` so that an empty string wasn't acceptable which was in contra to advice in #32.

Resolve #53 by adding allowEmpty property which checks for empty strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment