not null or not empty validation

9,195 views
Skip to first unread message

Bruno Reis

unread,
Nov 28, 2008, 2:53:12 PM11/28/08
to json-...@googlegroups.com
For the following:
schema
  {
      "description":"new user registration form",
      "type":"object",
      "properties": {
        "username":    {"type":"string","optional":false},
        "emailaddress":{"type":"string"},
        "password":    {"type":"string"},
        "password2":   {"type":"string"}
      }
    }

I see that
  {
        "username": "",
        "emailaddress": "asdf",
        "password": "asdf",
        "password2": "asdf"
    }

validates Ok

and
  {
        "emailaddress": "asdf",
        "password": "asdf",
        "password2": "asdf"
    }
dont

what I think is a nice behaviour.
But in web, using forms, its very common to validate a "not blank" or "not empty" string.

How should I define that on the schema?

Kris Zyp

unread,
Nov 28, 2008, 9:59:35 PM11/28/08
to json-...@googlegroups.com
I think you want:
"username": {"type":"string","minLength":1}
(note that optional defaults to false, so you don't need to set it to false)
Is that sufficient for your use case?
Kris

Bruno Reis

unread,
Nov 29, 2008, 8:22:22 AM11/29/08
to json-...@googlegroups.com
That is exactly what I was thinking. Just checking to see if there was another proper way to do that. Thanks.


2008/11/29 Kris Zyp <kri...@gmail.com>
Reply all
Reply to author
Forward
0 new messages