Validation Operators
Validations are client-side checks that run after a user submits an answer. They prevent the user from advancing if the answer does not meet the specified criteria.
How Validations Work
Section titled “How Validations Work”- The user fills in a question and presses the submit button.
- The
validationsarray on that question is evaluated in order. - If any validation fails, its
messageis displayed as an error (using the screen’serroranimation) and the user cannot proceed. - If all validations pass, the rules engine determines the next question.
Validation Structure
Section titled “Validation Structure”Each item in the validations array has this shape:
| Field | Type | Required | Description |
|---|---|---|---|
op |
string | Yes | The operator to apply (see table below) |
variable |
object | Yes | The value or reference to compare against |
variableEqual |
object | No | A second comparison value (for range checks) |
message |
string | Yes | Error message displayed when validation fails |
Variable Object
Section titled “Variable Object”The variable and variableEqual fields use the same structure as rule variables:
| Field | Type | Description |
|---|---|---|
type |
enum | static (fixed value) or dynamic (reference another question’s answer) |
value |
any | The comparison value (for static type) |
key |
string | Question ID whose answer to use (for dynamic type) |
Operators
Section titled “Operators”Validation operators match the rule comparison operators but are applied to the current question’s answer rather than determining routing.
Value Comparison
Section titled “Value Comparison”| Operator | Description | Example use case |
|---|---|---|
equals |
Answer must equal the value | “Confirm your email matches” |
notEquals |
Answer must not equal the value | “Cannot use a blacklisted value” |
greaterThan |
Answer must be greater than the value | “Coverage amount must be at least 10,000” |
lessThan |
Answer must be less than the value | “Age must be under 65” |
same |
Loose equality check | Flexible matching |
notSame |
Loose inequality check | Flexible exclusion |
Collection Comparison
Section titled “Collection Comparison”| Operator | Description | Example use case |
|---|---|---|
isIn |
Answer must be in the provided array | “Must select one of the supported countries” |
isNotIn |
Answer must not be in the provided array | “This country is not supported” |
contains |
Answer must contain the value | “Must include at least one coverage option” |
notContains |
Answer must not contain the value | “Cannot include excluded options” |
Existence Check
Section titled “Existence Check”| Operator | Description | Example use case |
|---|---|---|
isDefined |
Answer must not be null/undefined | “This field is required” |
isNotDefined |
Answer must be null/undefined | Conditional required (used with dynamic variables) |
Date Comparison
Section titled “Date Comparison”| Operator | Description | Example use case |
|---|---|---|
dateDiff |
Compare the date answer against a threshold | “Must be at least 18 years old” |
The dateDiff validation uses the same structure as rule-date:
{ "op": "dateDiff", "variable": { "type": "year", "value": 18, "dir": "gt", "key": "dateOfBirth" }, "message": "You must be at least 18 years old."}Country and Address
Section titled “Country and Address”| Operator | Description |
|---|---|
equalsOrContainsCountryCode |
Country code must match |
doesAddressMatch |
Address must match |
Examples
Section titled “Examples”Minimum age validation
Section titled “Minimum age validation”Ensure the user is at least 18 based on their date of birth:
{ "op": "dateDiff", "variable": { "type": "year", "value": 18, "dir": "gt", "key": "dateOfBirth" }, "message": "You must be at least 18 years old to purchase this insurance."}Minimum coverage amount
Section titled “Minimum coverage amount”Ensure the entered amount is above a threshold:
{ "op": "greaterThan", "variable": { "type": "static", "value": 10000 }, "message": "The minimum coverage amount is 10,000 EUR."}Value must be in allowed list
Section titled “Value must be in allowed list”Ensure the selected country is supported:
{ "op": "isIn", "variable": { "type": "static", "value": ["DE", "AT", "CH", "FR", "ES"] }, "message": "This product is only available in Germany, Austria, Switzerland, France, and Spain."}Cross-question validation (dynamic)
Section titled “Cross-question validation (dynamic)”Ensure the end date is after the start date by comparing against another question’s answer:
{ "op": "greaterThan", "variable": { "type": "dynamic", "key": "travelStartDate" }, "message": "The end date must be after the start date."}Required field
Section titled “Required field”Ensure the user has provided an answer:
{ "op": "isDefined", "variable": { "type": "static", "value": true }, "message": "This field is required."}Configuring in Strapi
Section titled “Configuring in Strapi”In the Strapi admin, each question has a validations repeatable component. For each validation entry:
- Set the op field to the desired operator.
- Configure the variable with either a static value or a dynamic reference to another question.
- Write a clear message that tells the user what went wrong and how to fix it.
Validations are evaluated in order. Place the most common failure cases first for the best user experience.
See also
Section titled “See also”- Configure Validations – how to add validations to questions in Strapi
- Rule Operators Reference – operators shared between validations and rules
- State Management – how answers are tracked and validated at runtime