Script API Tutorial

Email answer validation in «Open-ended» question

If your survey contains a question where you ask Respondent to provide his/her email address, it makes sense to validate the answer.

You can do it by applying special Regular Expression (a pattern used for matching character combinations in strings) to the response.

Please, check how it works in the example below

In order to reproduce this example, please undertake the following steps:

Create an "OpenEnded" question in which you ask Respondent to enter his/her email. Then launch the Script Editor and insert the following script into "OnValidate script" tab:

  • var answers = this.get();
  • var answer = answers[0].value;
  • var pattern = /^[a-zA-Z0-9\.]+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
  • var result = pattern.test(answer);
  • if (!result) {
  • return "Error Message";
  • }

After that change the "Error Message" token to message that you want to be displayed to respondent in case of entering incorrect email address.

Learn more at CoolTool knowledge base