Sorry, no results found for "".

Content modelling > Validations

Validations

Validations are a powerful tool to enforce a sound structure of your content.

They can help in different ways both editors and developers.

For editors

If you have an editorial team with different people working on content, you need to explain to everyone what are the rules they have to respect for the final page to look good and make sense. Also sometimes developers need to enforce some content rules to make everything work together.

With DatoCMS you can enforce all these rules on a per model/field basis, preventing editors to save content that would break pages or make poor content.

For example you can make certain fields as required, enforce certain text lengths and much more.

For developers

When you work with complex structured or semi-structured data structures often you need to write frontend code that deals with all the possible combinations of existing/non-existing code or more in general you need to double check if content matches certain rules.

You end up with code that is much more complex than necessary, with lots of if-statements to protect you from unfinished content and parse and validate other parts to be sure you are getting what you need.

With DatoCMS you can simplify your code and be more productive. By enforcing the right validations you'll always get the data that you need, in the format that you expect.

Remember that validations are enforced on every version of the record, even on saving a draft. This means that if you won't be able to save a record that is not satisfying all the validations. So be careful adding only what you really need.

But then on the code side you'll be sure that you'll always have the same structure and format, even while previewing draft content.

Field validations

Let's see together all the validations that are available on DatoCMS for each field.

Single line text

  • Required: field must be present

  • Unique: every record of the same model must have different content

  • Limit character count: you can specify the number of characters in different ways, i.e. at least 10, between 10 and 20, no more than 20, exactly 20

  • Match a specific pattern: text must be a valid URL, email address or match a specified regular expression

  • Accept only specified values: you can specify a list of values. If you do that, the field will display as a dropdown for the editor

Multiple-paragraph text

  • Required: field must be present

  • Limit character count: you can specify the number of characters in different ways, e.g. at least 10, between 10 and 20, no more than 20, exactly 20

  • Match a specific pattern: text must be a valid URL, email address or match a specified regular expression

Modular content field

  • Accept only a specified number of records: you can specify the number of records part of the modular content in different ways, e.g. at least 10, between 10 and 20, no more than 20, exactly 20. Moreover you can specify if the number of records must be multiple of a number

Single asset field

  • Required: field must be present

  • Accept only specified file size: enforce a certain asset size in different ways, e.g. between 500KB and 1MB, no more than 10MB, at least 1MB

  • Accept only specified extensions: allow only images, videos, documents or custom file extensions

  • Accept only specified image dimensions: enforce dimensions for image assets, e.g. between 500x500px and 1000x1000px or no more than 2000x2000px or at least 500x500px

  • Require alt and/or title: you can enforce presence of alt and/or title fields

Asset gallery field

  • Accept only a specified number of records: you can specify the number of records part of the asset gallery in different ways, e.g. at least 10, between 10 and 20, no more than 20, exactly 20. Moreover you can specify if the number of records must be multiple of a number

  • Accept only specified file size: enforce a certain asset size in different ways, e.g. between 500KB and 1MB, no more than 10MB, at least 1MB

  • Accept only specified extensions: allow only images, videos, documents or custom file extensions

  • Accept only specified image dimensions: enforce dimensions for image assets, e.g. between 500x500px and 1000x1000px or no more than 2000x2000px or at least 500x500px

  • Require alt and/or title: you can enforce presence of alt and/or title fields

External video field

  • Required: field must be present

Date field

  • Required: field must be present

  • Accept only specified date range: the specified date must be in a specified range, e.g. at least 30 March 2020, no more than 21 March 2020, between 21 and 30 March 2020

DateTime field

  • Required: field must be present

  • Accept only specified date range: the specified date must be in a specified range, e.g. at least 30 March 2020 12:00, no more than 21 March 2020 18:00, between 21 12:00 and 30 March 2020 18:00

Integer number field

  • Required: field must be present

  • Range: number must be within specified range, e.g. between 1 and 10, at least 5, no more than 10

Boolean field

No validations available

Geolocation field

  • Required: field must be present

Color field

  • Required: field must be present

Slug field

  • Reference field: pick a field from which the slug is automatically pre-filled

  • Required: field must be present

  • Unique: every record of the same model must have different content

  • Limit character count: you can specify the number of characters in different ways, i.e. at least 10, between 10 and 20, no more than 20, exactly 20

SEO meta tags field

  • Required: field must be present

  • Accept only specified file size: enforce a certain asset size in different ways, e.g. between 500KB and 1MB, no more than 10MB, at least 1MB

  • Accept only specified image dimensions: enforce dimensions for image assets, e.g. between 500x500px and 1000x1000px or no more than 2000x2000px or at least 500x500px

Single link field

  • Accept only specified model: pick one or more models from which you are allowed to pick links

  • Required: field must be present

  • Unique: every record of the same model must have different content

Multiple links field

  • Accept only specified model: pick one or more models from which you are allowed to pick links

  • Accept only a specified number of records: you can specify the number of links in different ways, e.g. at least 10, between 10 and 20, no more than 20, exactly 20. Moreover you can specify if the number of records must be multiple of a number

JSON field

  • Required: field must be present