This script will check a phone number entered by a participant and will display an error message if the format does not meet one of the following styles:
- (604)-123-1234
- 6041231234
- 604.123.1234
- 604-123-1234
- 604 123 1234
- (604) (123) (1234)
Detailed Steps
- Click the Questionnaire tab of your survey.
- Create an Open End question where participants will type in their phone number.
- Copy the script below into Notepad or any other text editor (e.g. Notepad++, Textpad).
- Replace Q_NAME with the question name of the Open End Question
- Insert the completed script into the Script section of your Open End question by doing the following
- In the Scripting section of the Open End question, click Edit Scripts. If the Open End question is inside a page, Edit the Script of the Page.
- Paste the script into the On Validate tab.
- Click Save.
- Validate and test your study.
Script
/*
Script Name: How do I validate the format of a 10 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(@"^\(?([0-9]{3})\)?[-. ]?\(?([0-9]{3})\)?[-. ]?\(?([0-9]{4})\)?$");
if( !reg.IsMatch(num)){
NewError("Please enter a valid phone number e.g. (640)-123-1234");
}
}
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.