What do you need help with?
Search the knowledge base, browse our resources, and visit our forum for more detailed information
Search the knowledge base, browse our resources, and visit our forum for more detailed information
Last updated: 6 Jun 2022
This feature allows you to avoid accidental or invalid answers, especially in
numeric questions (integer
or decimal
response types). However, validation
can be used on any question. Validation criteria are also sometimes referred to
as constraints.
For example, if you want to restrict a question about age to numbers between 0 and 130.
To add validation criteria for a specific question, go to Settings, then Validation Criteria.
You can directly add a condition or manually enter validation logic in XLSFrom code. The type of restrictions under “Add a condition” corresponds to the type of the questions (123 - numbers, text, date) selected. As seen from the example above, the question type is number and the validation criteria restricts the response to be greater than 3 and less than or equal to 30. The Error Message (optional) is the message your interviewer sees when they enter an invalid response.
Validation criteria in XLSForm needs to be entered in specific syntax.
Criteria |
Description |
---|---|
|
Response must be greater than 17 |
|
Response must be greater than or equal to 18 |
|
Response must be between 17 and 130 |
In the validation criteria syntax,.
refers to the current question.
${some_question}
refers to the fixed name
of a question, which needs to be
set in the Question Options and then surrounded by ${}
. See below example:
survey
type |
name |
label |
constraint |
constraint_message |
---|---|---|---|---|
integer |
Q1 |
Please enter your work ID |
. > 0 and . < 100 |
ID cannot be 0 and must be less than 100 |
integer |
Q2 |
Total number of workers |
||
integer |
Q3 |
Total number of male workers |
. <= ${Q2} |
Total number of male workers should not exceed the total number of workers! |
integer |
Q4 |
Total number of female workers |
. <= ${Q2} |
Total number of female workers should not exceed the total number of workers! |
survey |
Examples of More Advanced Validation Criteria
Criteria |
Description |
---|---|
|
Response must be between 17 and 130 or be equal to 999. (The code 999 is often used for non-responses.) |
|
When answering ‘yes’ to the question |
|
Response ‘none’ can’t be combined with the two other options of this |
There are many other combinations possible, including advanced mathematical calculations. See here for more details.
Did you find what you were looking for? Was the information clear? Was anything missing?
Share your feedback to help us improve this article!
KoboToolbox is maintained by Kobo Inc.