Skip to main content

Input Validation

Qlarr provides built-in validation rules and support for custom validation expressions to ensure data quality.

How It Works

Validation is configured per question in the editor's Validation tab. Each rule generates a validity instruction — a JavaScript expression that the Survey Engine evaluates at runtime. When a rule fails, the configured error message is shown to the respondent.

Validation runs in the browser via the generated state machine, providing instant feedback as the respondent fills in the survey.

Built-in Validation Rules

The available rules depend on the question type:

Text Questions

RuleDescription
RequiredField must not be empty
Min character lengthMinimum number of characters
Max character lengthMaximum number of characters
Pattern (regex)Must match a regular expression
ContainsMust contain a specific string
Does not containMust not contain a specific string

Number Questions

RuleDescription
RequiredField must not be empty
BetweenValue must be within a range
Not betweenValue must be outside a range
Less than / Less than or equalUpper bound
Greater than / Greater than or equalLower bound
Equals / Not equalExact match or exclusion

Long Text (Paragraph) Questions

RuleDescription
RequiredField must not be empty
Min word countMinimum number of words
Max word countMaximum number of words
Contains / Does not containString presence checks

Email Questions

RuleDescription
RequiredField must not be empty
Email patternMust be a valid email format (built-in)
Min/Max character lengthLength constraints

Choice Questions (Multiple Choice)

RuleDescription
Min selected optionsMinimum number of selections
Max selected optionsMaximum number of selections
Exact option countMust select exactly N options

Ranking Questions

RuleDescription
Min ranked itemsMinimum number of items to rank
Max ranked itemsMaximum number of items to rank
Exact ranking countMust rank exactly N items

Array Questions (Matrix)

RuleDescription
RequiredAll rows must be answered
One response per columnEach column can only be selected once across rows

File Upload / Photo / Video

RuleDescription
RequiredA file must be uploaded
Max file sizeMaximum file size
File typesAllowed file extensions (file upload only)

Custom Validation Rules

For validation logic that goes beyond built-in rules, you can write custom JavaScript expressions:

  1. Open the question's Validation tab
  2. Click Add Custom Rule at the bottom
  3. Give the rule an ID (used internally)
  4. Write a JavaScript expression that returns true when the input is valid
  5. Set a custom error message for each language

Custom rules can reference other questions. For example, to ensure a confirmation email matches the original:

Qemail.value === Qemail_confirm.value

Or to validate that a number is a multiple of 5:

Qcount.value % 5 === 0

Validation Error Messages

Each validation rule has a configurable error message. For multilingual surveys, you can set a different message per language. The message is displayed below the question when validation fails.

Validation Timing

Validation behavior depends on the survey's navigation settings:

  • Per question (default) — validation runs when the respondent moves to the next question or page
  • On submit only — enable Enforce Validation Only on Submit in the survey settings to defer all validation until the respondent submits the survey