This script checks whether the email address entered by participants is in a valid format. If the email address format is invalid, an error message will appear. Here, "Open End" refers to the following question types:
- Short Answer
- Long Answer
Tip: When should you use a script with an Open End question instead of the Email question type? One potential use case is if you want to add the email addresses collected by the question as a profile variable. Text and Identity profile variables can both work with open-ended data.
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.
- If necessary, replace Please provide a valid email address with the translated text.
- Click Save.
- Preview and test your survey.
Script
/* Script Name: How do I validate the format of an email address in an Open End question? (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. */ const emailC = response.getDataPoint("Q_NAME"); const emailCValue = emailC.get(); var regexpcode = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; //If the inputString is NOT a match if (!regexpcode.test(emailCValue)) { response.setError("Q_NAME", "Please provide a valid email address."); }
Comments
0 comments
Article is closed for comments.