Validations
Validations are objects placed in a field’s validations array. Each validation object can contain one or more rules. Different field types support different validation rules.
Text validations
Section titled “Text validations”Text validations apply to Symbol and Text fields.
Unique
Section titled “Unique”Ensures no two entries have the same value for this field.
{ id: "slug", name: "Slug", type: "Symbol", required: true, validations: [{ unique: true }],}Size (character length)
Section titled “Size (character length)”Restricts the string length. Both min and max are optional.
{ id: "title", name: "Title", type: "Symbol", required: true, validations: [ { size: { min: 1, max: 120 } }, ],}Regular expression
Section titled “Regular expression”Validates the value against a regex pattern. The optional flags property accepts standard regex flags like "i" for case-insensitive.
{ id: "slug", name: "Slug", type: "Symbol", required: true, validations: [ { regexp: { pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$" } }, ],}With flags:
{ id: "code", name: "Code", type: "Symbol", required: true, validations: [ { regexp: { pattern: "^[A-Z]{3}-\\d{4}$", flags: "i" } }, ],}Enumeration (in)
Section titled “Enumeration (in)”Restricts the value to a predefined list.
{ id: "status", name: "Status", type: "Symbol", required: true, validations: [ { in: ["draft", "review", "published", "archived"] }, ],}Combining text validations
Section titled “Combining text validations”Each validation object in the array is applied independently. You can combine multiple rules:
validations: [ { size: { min: 1, max: 255 } }, { unique: true }, { regexp: { pattern: "^[a-z0-9-]+$" } },]Number validations
Section titled “Number validations”Number validations apply to Integer and Number fields.
Restricts the value to a numeric range. Both min and max are optional.
{ id: "rating", name: "Rating", type: "Integer", required: true, validations: [ { range: { min: 1, max: 5 } }, ],}Open-ended ranges are supported:
// Minimum onlyvalidations: [{ range: { min: 0 } }]
// Maximum onlyvalidations: [{ range: { max: 100 } }]Enumeration (in)
Section titled “Enumeration (in)”Restricts the value to a predefined list of numbers.
{ id: "columns", name: "Columns", type: "Integer", required: true, validations: [ { in: [1, 2, 3, 4, 6, 12] }, ],}Unique
Section titled “Unique”Ensures no two entries share the same number value.
{ id: "sortOrder", name: "Sort Order", type: "Integer", required: true, validations: [{ unique: true }],}Link validations
Section titled “Link validations”Link validations apply to Link fields (both Entry and Asset link types).
Content type restriction
Section titled “Content type restriction”Limits which content types can be linked. This is the most common link validation.
{ id: "author", name: "Author", type: "Link", linkType: "Entry", required: true, validations: [ { linkContentType: ["person", "organization"] }, ],}MIME type group restriction
Section titled “MIME type group restriction”Limits which types of assets can be linked. Common groups: "image", "audio", "video", "plaintext", "richtext", "spreadsheet", "pdfdocument", "archive", "code", "markup", "presentation".
{ id: "heroImage", name: "Hero Image", type: "Link", linkType: "Asset", required: true, validations: [ { linkMimetypeGroup: ["image"] }, ],}Multiple MIME type groups:
validations: [ { linkMimetypeGroup: ["image", "video"] },]Image dimensions
Section titled “Image dimensions”Restricts the pixel dimensions of linked image assets.
{ id: "thumbnail", name: "Thumbnail", type: "Link", linkType: "Asset", required: true, validations: [ { linkMimetypeGroup: ["image"] }, { assetImageDimensions: { width: { min: 200, max: 800 }, height: { min: 200, max: 800 }, }, }, ],}You can specify only width or only height, and within each, only min or only max:
validations: [ { assetImageDimensions: { width: { min: 1200 }, }, },]File size
Section titled “File size”Restricts the file size of linked assets in bytes.
{ id: "document", name: "Document", type: "Link", linkType: "Asset", required: false, validations: [ { linkMimetypeGroup: ["pdfdocument"] }, { assetFileSize: { min: 0, max: 10_485_760 } }, // 10 MB ],}Array validations
Section titled “Array validations”Array validations apply to Array fields and control the number of items.
Size (item count)
Section titled “Size (item count)”Restricts how many items the array can contain.
{ id: "tags", name: "Tags", type: "Array", required: false, items: { type: "Symbol" }, validations: [ { size: { min: 1, max: 10 } }, ],}Note that validations on the items themselves go inside items.validations, while validations on the array go in the top-level validations:
{ id: "relatedArticles", name: "Related Articles", type: "Array", required: false, items: { type: "Link", linkType: "Entry", validations: [ { linkContentType: ["article"] }, // validates each item ], }, validations: [ { size: { min: 1, max: 5 } }, // validates the array itself ],}Rich text validations
Section titled “Rich text validations”Rich text validations control which formatting options and embedded content types are available in a RichText field.
Enabled marks
Section titled “Enabled marks”Controls which inline formatting marks are available. There are 7 marks:
| Mark | Value |
|---|---|
| Bold | "bold" |
| Italic | "italic" |
| Underline | "underline" |
| Code | "code" |
| Superscript | "superscript" |
| Subscript | "subscript" |
| Strikethrough | "strikethrough" |
{ id: "body", name: "Body", type: "RichText", required: true, validations: [ { enabledMarks: ["bold", "italic", "underline", "code"] }, ],}Pass an empty array to disable all formatting:
validations: [{ enabledMarks: [] }]Enabled node types
Section titled “Enabled node types”Controls which block-level elements are available. Common node types:
| Node type | Value |
|---|---|
| Paragraph | "paragraph" |
| Heading 1–6 | "heading-1" through "heading-6" |
| Ordered list | "ordered-list" |
| Unordered list | "unordered-list" |
| Blockquote | "blockquote" |
| Horizontal rule | "hr" |
| Embedded entry (block) | "embedded-entry-block" |
| Embedded entry (inline) | "embedded-entry-inline" |
| Embedded asset (block) | "embedded-asset-block" |
| Hyperlink | "hyperlink" |
| Entry hyperlink | "entry-hyperlink" |
| Asset hyperlink | "asset-hyperlink" |
| Table | "table" |
{ id: "body", name: "Body", type: "RichText", required: true, validations: [ { enabledNodeTypes: [ "paragraph", "heading-2", "heading-3", "ordered-list", "unordered-list", "blockquote", "hyperlink", "embedded-entry-block", "embedded-asset-block", ], }, ],}Embedded entry restrictions (nodes)
Section titled “Embedded entry restrictions (nodes)”The nodes property restricts which content types can be embedded for specific node types.
{ id: "body", name: "Body", type: "RichText", required: true, validations: [ { nodes: { "embedded-entry-block": [ { linkContentType: ["cta", "codeBlock", "videoEmbed"] }, ], "embedded-entry-inline": [ { linkContentType: ["person"] }, ], }, }, ],}Combining rich text validations
Section titled “Combining rich text validations”You can combine marks, node types, and node restrictions in a single schema:
{ id: "body", name: "Body", type: "RichText", required: true, validations: [ { enabledMarks: ["bold", "italic", "code"] }, { enabledNodeTypes: [ "paragraph", "heading-2", "heading-3", "ordered-list", "unordered-list", "hyperlink", "embedded-entry-block", ], }, { nodes: { "embedded-entry-block": [ { linkContentType: ["cta", "codeBlock"] }, ], }, }, ],}