This script checks whether an Open End question only contains text and no numbers. If a participant enters a response that contains numbers, an error message will appear.
Note:
-
This script will not work for Number question. Here, "Open End" refers to the following question types:
- Short Answer
- Long Answer
Detailed Steps
- In your survey, add a Page element.
- Add an Open End question to the Page element.
- Open the Page element for editing and click the Scripting button.
- Copy and paste the script below into the On Complete tab.
- Replace Q_NAME with the name of your Open End question.
- Click Save.
- Preview and test your survey.
Script
/* Script Name : How do I validate an Open End question to only have text (no numbers)? (Modern Surveys) To ensure your script works as expected, always copy the original script from the Script Library found in the Alida Help Center. Failure to use the latest script from the script library may cause unexpected results. */ //declaring functions to test for only numbers function onlyLetters(str) { return /^[A-Za-z]*$/.test(str); } //getting reference to the open end questions var vq = response.getDataPoint("Q_NAME"); //validating the entered text by running it through the declared functions above if(!onlyLetters(vq.get())){ console.log("false"); response.setError("Q_NAME","Please provide a valid response of only letters."); }
Comments
0 comments
Article is closed for comments.