Validation schema example
This schema example demonstrates various validations available for text, numbers and arrays.
-
The
simplestringwithmaxandminproperty usesminLengthandmaxLengthto constrain the length of the string. This property is also included in the properties listed as required, so a valid value must be entered in the property before it can be saved. -
The
dateWithPatternandurlslugproperties demonstrate how to constrain the value entered using a regular expression defined by the pattern keyword. You can find out more about regular expressions in JSON Schema in the JSON Schema documentation. -
The
numbervalidationexampleshows how to use the multipleOf keyword, for a number that must be a multiple of 10 -
The
stringlistofenumsdemonstrates how to use an enum to constrain the values that can be added to a list. TheuniqueItemskeyword is also used to ensure that each value can only be chosen once. This property is also required, so a valid value must be entered before the the content item can be saved. Users have a choice of selecting "none" if the array uses an enum. -
The
stringArraymust contain a string with a length of 10 or more characters - validated using thecontainskeyword. -
The
numberArrayproperty must contain an integer with a value of at least 10 - validated using thecontainskeyword.
Pre-requisitesLink copied!
None. This is a self contained schema.
How to useLink copied!
You can use the validations demonstrated in this schema for your own properties.