This script will check a phone number entered by a respondent and will display an error message if the number is not 11 digits long with no spaces in between.
Note: This script will not work for a Numeric question - the question must be an Open End question.
Detailed Steps
- Click on the Questionnaire tab of your study.
- Create your Open End question, where respondents will type in their phone number.
- Copy the script below into Notepad or any other text editor (e.g. Notepad++, Textpad).
- Change Q_NAME to the name of your Open End question.
- Insert the completed script into the Script section of the Open End question by doing the following:
- Select the Open End question in the Questionnaire Tree.
- In the Scripting section of the Open End question, click Edit Scripts.
- Paste the script into the On Validate tab.
- Click Save.
- Click Validate and test your survey.
Script:
/*
Script Name: How do I validate the format of an 11 digit telephone number?
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.
*/
if (!IsATR){
String num = Q_NAME.ToString().Trim();
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\d{11}");
if(!reg.IsMatch(num) || num.Length != 11){
NewError("Please enter a valid phone number. It should be 11 digits long with no spaces between numbers");
}
}
Note: ATR will bypass the validation script, so please be aware that ATR data will not be accurate for this setup. It will need to be checked manually through the link.
Comments
0 comments
Article is closed for comments.