Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Dealing with errors > Using a custom validation function > General rules for validation functions
 
General rules for validation functions
All references to examples refer to the example in Using a custom validation function.
Referring to the current question
The name of the question on which the validation function is being run is passed to the function in the Question parameter. Whenever you want to refer to the current question inside the function, use Question rather than the question name itself. This allows you to write a general purpose validation function that can be used by more than one question. In the example, you have statements such as:
If (<question>.Response.ContainsAny(<question>.Categories[{BrandSetA}]) ...
which becomes:
If (SelectBrands.Response.ContainsAny(SelectBrands.Categories[{BrandSetA}]) ...
when the function is run on the SelectBrands question.
Referring to other questions
Functions called for one question do not normally have access to other questions. However, in the case of the validation function, the names of all questions in the script are passed to the function in the IOM parameter. If you want to refer to another question inside the function, type its name as IOM.Questions.<question_name>. The function in the example needs to refer to the SelectBrandError information item to pick up the error message, which it does using:
IOM.Questions.SelectBrand
Return values
The function must return a True or False value indicating whether or not validation was successful.
Number of validation attempts
You can control the number of attempts respondents can make at giving a valid answer. The Attempts parameter has an initial value of 1 and is incremented every time the function returns False. It is reset to 1 when the function returns True. You can write statements inside the function that check the Attempts parameter and perhaps accept the most recent invalid response if the number of attempts is greater than a given value.
For further information about the validation function, see:
IValidation_Function
See also
Using a custom validation function