Professional > Interview scripting > Writing interview scripts > Dealing with errors > How validation works
 
How validation works
The .Ask() method has built-in response validation and error processing that is largely invisible to respondents. As far as respondents are concerned, if they enter or select invalid responses, the interviewing program displays the question with an explanatory error message and waits for them to correct the error. The following illustration shows the error that is displayed when a respondent chooses an exclusive response and another response from a multiple choice list:
The CannotCombine error message is displayed above the question label of a categorical question.
This topic provides a more detailed description of what happens behind the scenes to help you understand what changes you can make to the way validation works. The following diagram summarizes the procedure:
Response validation procedure
The interviewing program has a set of error messages that it uses to report validation errors such as out-of-range numeric responses, or a multiple choice selection that includes an exclusive response with other responses. These messages are known as the standard error messages, and they are available to all questions in a script. For more information, see Standard error messages.
Each question has a collection item called Qname.Errors that holds the error message, if any, to be displayed for that question. A question’s Errors collection is empty until the respondent enters an incorrect answer. At this point, the interviewing program selects the appropriate error message and inserts it in the Errors collection ready to display with the question. (The Errors collection is always displayed with each question but because it is usually empty you are not aware of it.) For example, if the Age question expects a value between 20 and 50 and the respondent enters 59, the interviewing program copies the error message for an out-of-range numeric response into Age.Errors, and then redisplays the question with the error message in red above it.
You can modify this procedure in the following ways:
Define your own message texts to use instead of the standard message texts; for example, if you would prefer to explain an error in a different way. For more information, see Replacing the standard message texts.
Define your own validation tests, optionally with your own error messages; for example, if the standard tests and/or error messages do not cover the type of validation you want to perform. For more information, see Using a custom validation function.
To change the color or other visual characteristics of the error text, you can use styles and templates. To specify the position of the error message text on the page, use an <mrData> instruction in a template. For more information, see Questions, responses, and error messages.
See also
Dealing with errors