Custom Form Validation Using an Event
Event Handler vs Expressions
onValidateQuestion event, you need to implement a corresponding event handler. Users have no access to this handler and therefore cannot disable custom validation.
onValidateQuestion event handler accepts the survey as the first argument and an object with the following fields as the second argument:
question- The question being validated.
name- The question's name.
value- A question value being validated.
error- An error message that you should specify if validation fails.
In this custom form validation example, the form field accepts only e-mail addresses hosted at
surveyjs.io. A callback attached to the
onValidateQuestion event handler validates the entered e-mail address and assigns an error message to the
options.error field if the address is invalid.
onValidateQuestion event may occur and run validation at different points in your application, depending on the
checkErrorsMode property. In this demo, the event occurs immediately after you change the form field value because
checkErrorsMode is set to
"onValueChanged". If you do not set this property, validation activates before a user proceeds to the next page or completes the survey.