Field validations

Field validations allow you to control the content which is entered within a field. Each validation has a set of properties which are described in more detail below. A common property across all validations is the message. Messages are optional on validations and if not specified, a default validation error message is returned from the API.

Content validations

When creating, updating or publishing an entry, if a field has been populated then the value will be evaluated against the following validations. If the field hasn't been populated then the validation is ignored. This is to allow for partial completion of an entry when saving.

Required validations

When publishing an entry, in addition to the above content validations, required validations are evaluated. If a required field hasn't been populated at this stage then the entry will fail to publish and a validation message will be returned.

Allowed validations for field types

DataType DataFormat Validations
string   Required
MaxLength
MinLength
RegEx
AllowedValues
taxonomy Required
TaxonomyRoot
markup Required
stringArray   Required
MaxLength
MinLength
RegEx
AllowedValues
MaxCount
MinCount
taxonomy Required
TaxonomyRoot
MaxCount
MinCount
integer   Required
Max
Min
integerArray   Required
Max
Min
MaxCount
MinCount
decimal   Required
Max
Min
DecimalPlaces
MaxCount
MinCount
decimalArray   Required
Max
Min
DecimalPlaces
datetime   Required
Max
Min
PastDateTime
object   Required
image, quote Required
RequiredFields
entry, asset Required
RequiredFields
objectArray   Required
field (composer) Required
AllowedContentTypes
entry, asset Required
RequiredFields
MaxCount
MinCount

Required

Description

Validates that a field value must be set.

Applies to

All fields.

Definition

"validations": {
    "required": {
        "message": {
            "en-GB": "A value is required"
        }
    }
}

MaxLength

Description

Validates a maximum length for a string based field.

Applies to

string, stringArray

Definition

"validations": {
    "maxLength": {
        "value": 50,
        "message": {
            "en-GB": "Maximum length of 50"
        }
    }
}

MinLength

Description

Validates a minimum length for a string based field.

Applies to

string, stringArray

Definition

"validations": {
    "minLength": {
        "value": 10,
        "message": {
            "en-GB": "Minimum length of 10"
        }
    }
}

Min

Description

Validates a minimum value for a field.

Applies to

integer, integerArray, decimal, decimalArray, dateTime, dateTimeArray

Definition

"validations": {
    "min": {
        "value": 5,
        "message": {
            "en-GB": "The value is too low. A minimum of 5 is required"
        }
    }
}

Max

Description

Validates a maximum value for a field.

Applies to

integer, integerArray, decimal, decimalArray, dateTime, dateTimeArray

Definition

"validations": {
    "max": {
        "value": 100,
        "message": {
            "en-GB": "The value is too high. A maximum of 100 is allowed"
        }
    }
}

Regex

Description

Executes a regular expression on a string based field.

Applies to

string, stringArray

Definition

"validations": {
    "regex": {
        "pattern": "[a-zA-Z]+",
        "message": {
            "en-GB": "The value does not match the regex"
        }
    }
}

AllowedValues

Description

Validates that only the allowed values have been set as the field value.

Applies to

string, stringArray

Definition

"validations": {
    "allowedValues": {
        "values": [
            {
                "en-GB": "Red",
                "fr-FR": "Rouge"
            },
            {
                "en-GB": "Black",
                "fr-FR": "Noir"
            }
        ],
        "message": {
            "en-GB": "The selected value is not allowed",
            "fr-FR": "La valeur sélectionnée n'est pas autorisée"
        }
    }
}

RequiredFields

Description

Validates that a field is required in object types. For example, the source is required in the Quote field.

Applies to

quote, image

Definition

"validations": {
    "requiredFields": {
        "fields": [
            {
                "name": "source",
                "message": {
                    "en-GB": "A source is required"
                }
            },
            {
                "name": "quote",
                "message": {
                    "en-GB": "A quote is required"
                }
            },
            {
                "name": "caption",
                "message": {
                    "en-GB": "An image caption is required"
                }
            }
        ]
    }
}

AllowedFieldTypes

Description

Specifies which fields are available within a composer and validates that only those are set in the field value.

Applies to

composer

Definition

"validations": {
    "allowedFieldTypes": {
        "fields": [
            {
                "id": "text",
                "name": {
                    "en-GB": "Text"
                },
                "description": null,
                "dataType": "string",
                "dataFormat": "text",
                "validations": {}
            },
            {
               "id": "markup",
                "name": {
                    "en-GB": "Markup"
                },
                "description": null,
                "default": null,
                "dataType": "string",
                "dataFormat": "html",
                "validations": {}
            }
        ],
        "message": {
            "en-GB": "The field type is not allowed"
        }
    }
}

TaxonomyRoot

Description

Specifies the root taxonomy node that values can be selected from.

Applies to

taxonomy, taxonomyArray

Definition

"validations": {
    "taxonomyRoot": {
        "key": "0/1/2",
        "message": {
            "en-GB": "The taxonomy node is not a descendant of the allowed root"
        }
    }
}

AllowedContentTypes

Description

Specifies the allowed content type or asset types selectable in the field.

Applies to

entry, entryArray, asset, assetArray

Definition

"validations": {
    "allowedContentTypes": {
        "contentTypes": [
            "PDF",
            "image"
        ],
        "message": {
            "en-GB": "The asset type is not allowed"
        }
    }
}

PastDateTime

Description

Specifies that the date time value must be in the past. To allow future dates times, do not apply this validation to the field.

Applies to

dateTime, dateTimeArray

Definition

"validations": {
    "pastDateTime": {
        "message": {
            "en-GB": "The date must be in the past"
        }
    }
}

DecimalPlaces

Description

Validates how many decimal places a decimal based field value is allowed to have.

Applies to

decimal, decimalArray

Definition

"validations": {
    "decimalPlaces": {
        "value": 3,
        "message": {
            "en-GB": "The value must be to 3 decimal places"
        }
    }
}

MaxCount

Description

Validates the maximum amount of elements an array type field can have.

Applies to

dateTimeArray, decimalArray, integerArray, objectArray, stringArray

Definition

"validations": {
    "maxCount": {
        "value": 3,
        "message": {
            "en-GB": "The value cannot contain more than 3 node keys"
        }
    }
}

MinCount

Description

Validates the minimum amount of elements an array type field can have.

Applies to

dateTimeArray, decimalArray, integerArray, objectArray, stringArray

Definition

"validations": {
    "minCount": {
        "value": 3,
        "message": {
            "en-GB": "The value cannot contain less than 3 node keys"
        }
    }
}

results matching ""

    No results matching ""