This script checks whether a French or German postal code entered by a participant is valid. If the format is incorrect, an error message will appear. 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.
- Replace Please provide a valid postal code with the translated text.
- Click Save.
- Preview and test your survey.
Script
/* Script Name: How do I validate the format of a French or German postal code? (Modern Surveys) To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */ const pcode = response.getDataPoint("Q_NAME"); const pcodeValue = pcode.get(); var regexpcode = /^\d{5}$/; //If the inputString is NOT a match if (!regexpcode.test(pcodeValue)) { response.setError("Q_NAME", "Please provide a valid postal code"); }
Comments
0 comments
Article is closed for comments.