Difference between revisions of "Force email address"
(→Code) |
(→Code) |
||
Line 28: | Line 28: | ||
return true; | return true; | ||
} | } | ||
+ | questioncheck = extendedQuestionCheck; | ||
</source> | </source> |
Revision as of 17:04, 20 January 2010
Challenge
You want the respondent to write an e-mail address.The script needs to validate if a string input is in email address format
Example
Code
1 var normalQuestionCheck = questioncheck;
2 function extendedQuestionCheck()
3 {
4 var valid = normalQuestionCheck();
5 if (valid)
6 {
7 var val;
8 //The value below is the index value of the sub question where your e-mail question is asked.
9 //In this case we use the sub question has index 2
10 val = document["query"][quest.label + "." + 2].value;
11 if (val.length > 0)
12 valid = validateEmail(val);
13 }
14 if (!valid)
15 {
16 alert('Wrong email address format');
17 return false;
18 }
19 return true;
20 }
21 questioncheck = extendedQuestionCheck;