Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Here are some example validation rules.

Length

Code Block
languagejson
{
  "type": "string",
  "minLength": 2,
  "maxLength": 3
}

Valid: hi

Regular expression

Code Block
{
   "type": "string",
   "pattern": "^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$"
}

Valid: 555-1212

Date and time

Code Block
languagejson
{
   "type": "string",
   "format": "date-time"
}

Valid: 2018-11-13T20:20:39+00:00

Time (draft)

Code Block
languagejson
{
   "type": "string",
   "format": "time"
}

Valid: 20:20:39+00:00

Date (draft)

Code Block
languagejson
{
   "type": "string",
   "format": "date"
}

Valid: 2018-11-13

Email

Code Block
languagejson
{
   "type": "string",
   "format": "email"
}

Valid: my@email.de

Hostname

Code Block
languagejson
{
   "type": "string",
   "format": "hostname"
}

Valid: google.com

Uri

Code Block
languagejson
{
   "type": "string",
   "format": "uri"
}

Valid: https://google.com

Required fields

Code Block
{
  "type": "object",
  "properties": {
    "name":      { "type": "string" },
    "email":     { "type": "string" },
    "address":   { "type": "string" },
    "telephone": { "type": "string" }
  },
  "required": ["name", "email"]
}

...