Validation stops participants submitting an answer that cannot be right — a percentage over 100, an email address with no @, a budget split that does not add up. It is worth the effort: an answer you reject at the time is one you do not have to clean up, or throw away, after fieldwork.
LimeSurvey gives you three levels, and you should reach for them in this order:
Open a question, and in the Question settings panel choose the Advanced tab. Mandatory has three settings:
Soft is worth knowing about: it lets you press for an answer without hard-blocking someone who genuinely cannot give one.
The Advanced tab shows the attributes that apply to the question type you are editing, so what you see changes with the type. A question that takes typed text — an Array (Texts), for example — offers Max characters. Set it and the participant simply cannot type more.
The classic question editor groups the logic-related attributes under its Logic section, including:
Always try these before writing an equation: they are quicker, and a colleague can understand them at a glance.
A question validation equation is an ExpressionScript expression that must be true before the answer is accepted. It is the escape hatch for any rule the ready-made attributes cannot express.
The field lives in the classic question editor, under Logic → Question validation equation — so this is one of the settings you step out of the new editor to reach.
Refer to questions by their question code — whatever you set as the code, such as q1 or part1 — and to a sub-question as the question code, an underscore, and the sub-question code, as in q1_SQ001.
A number must be between 1 and 100:
q1.NAOK >= 1 && q1.NAOK <= 100
Three amounts must not exceed a budget (here the sub-questions of Test are A_1, A_2 and A_3):
sum(Test_A_1.NAOK, Test_A_2.NAOK, Test_A_3.NAOK) <= 1000
Two figures must add up to exactly 100:
(part1.NAOK + part2.NAOK) == 100
Only require an email address when a name was given:
is_empty(name.NAOK) || !is_empty(email.NAOK)
Note that ExpressionScript has no comment syntax — there is no //. Everything in the field is part of the expression, so do not paste explanatory notes alongside it.
Two syntax rules save most of the debugging:
.NAOK on values you reference. It means "not applicable is OK", so the expression still evaluates when a question was skipped or hidden. Without it, one unanswered question can make the whole equation fail silently.Useful functions include sum(), count() (how many were answered), is_empty(), and if(). The editor highlights unknown variable names and function errors in red, which is the fastest way to catch a typo.
An equation only tells LimeSurvey what is wrong. The Question validation tip tells the participant — and without it they see a rejection with no explanation and abandon the survey.
Write the rule, not the error: "Please enter a number between 1 and 100" or "The three amounts must add up to 1000 or less." The tip is shown with the question and highlighted when validation fails.
Validation is the easiest thing in a survey to get subtly wrong, and the damage only shows once real people are stuck. Open the preview (the eye icon) and deliberately try to break each rule: enter a value that should pass, then one that should fail, and confirm the tip that appears actually explains what to do.
Pay particular attention to skipped questions: check that your rule does not block someone who legitimately left an earlier question blank. That is the most common validation bug, and .NAOK is usually the fix.