Using a custom validation function
You'll need a custom validation function whenever you want to perform validation that is not covered by any of the standard error messages. For example, suppose you have a response list with two subsections, and you want respondents to select answers from one section or the other only. There is no standard message that you can display if a respondent selects responses from both sections so you'll need to create one of your own, and then write the necessary code to test the answers chosen and apply the message if appropriate.
See also