Skip to content

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.

  1. The user fills in a question and presses the submit button.
  2. The validations array on that question is evaluated in order.
  3. If any validation fails, its message is displayed as an error (using the screen’s error animation) and the user cannot proceed.
  4. If all validations pass, the rules engine determines the next question.

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

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)

Validation operators match the rule comparison operators but are applied to the current question’s answer rather than determining routing.

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
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”
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)
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."
}
Operator Description
equalsOrContainsCountryCode Country code must match
doesAddressMatch Address must match

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."
}

Ensure the entered amount is above a threshold:

{
"op": "greaterThan",
"variable": {
"type": "static",
"value": 10000
},
"message": "The minimum coverage amount is 10,000 EUR."
}

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."
}

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."
}

Ensure the user has provided an answer:

{
"op": "isDefined",
"variable": {
"type": "static",
"value": true
},
"message": "This field is required."
}

In the Strapi admin, each question has a validations repeatable component. For each validation entry:

  1. Set the op field to the desired operator.
  2. Configure the variable with either a static value or a dynamic reference to another question.
  3. 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.