x

Main chapters

  1. Get started
  2. Workspace
  3. Editor
  4. Question types
  5. Share
  6. Results
  7. Configuration
  8. Installation and updates
  9. Profile and personal settings
  10. Account and billing
  11. FAQs
  12. Development
 Actions

Validation: make sure the answers you get are usable

From LimeSurvey Manual

Validation checks answers before participants can move on. It ranges from requiring an answer to rules you write yourself as an equation. Everything is set per question, in both survey editors:

  • In the new editor, select the question and use Question settings on the right. Many validation settings are only in the Advanced view: click Advanced and then Expand all to see them all.
  • In the classic editor, open the question and click Edit. The settings are in the panel on the right: General settings and the sections Logic and Input.

Require an answer

Set Mandatory (in the classic editor under General settings):

  • On: participants must answer before they can go to the next page.
  • Soft: participants who skip the question are reminded once, then they can go on without an answer.
  • Off: the answer is optional. This is the default.

Use the limits of the question type

Most question types have limits of their own:

Setting Section Question types
Maximum characters New editor: General. Classic editor: Input Text and number questions
Minimum value, Maximum value and Integer only Input Number questions
Minimum answers and Maximum answers Logic Multiple choice questions
Input validation New editor: General. Classic editor: General settings Text and number questions. A regular expression the answer must match, for example /^[0-9]{5}$/ for a five-digit postal code.

Write your own rule

  1. Select the question. In the new editor, click Advanced in Question settings. In the classic editor, click Edit.
  2. Open Logic (1).
  3. Type the rule into Question validation equation (2). The answer is accepted when the equation is true. The example strlen(Q002) >= 20 accepts answers of at least 20 characters.
  4. Type the message for participants into Question validation tip (3), for example "Please write at least 20 characters."
  5. In the classic editor, click Save. The new editor saves your changes automatically.


Logic section of Question settings with numbered markers on Logic, a Question validation equation for at least 20 characters and the Question validation tip


The picture shows the new editor. The equation names the question by its code, here Q002. See Regenerate question codes. Question types with subquestions also have Subquestion validation equation and Subquestion validation tip, which check each subquestion on its own.

The equation is an expression of ExpressionScript. Type it without curly brackets.

Validation works in the running survey, not in the editor. Test it with Preview survey (the eye icon in the top bar of the new editor): give a wrong answer and check that your tip appears.

FAQ

What is the difference between On and Soft?

On blocks the next page until the question is answered. Soft shows a reminder once and then lets participants go on, which keeps them in the survey while still nudging for an answer.

Where are the validation settings of the classic editor in the new editor?

In Question settings, view Advanced: Question validation equation and Question validation tip under Logic, Input validation under General.

See also