More actions
Line 8: | Line 8: | ||
== Code == | == Code == | ||
<source lang="javascript" line="1"> | <source lang="javascript" line="1"> | ||
var normalQuestionCheck = questioncheck; | var normalQuestionCheck = questioncheck; | ||
function extendedQuestionCheck() | function extendedQuestionCheck() | ||
Line 30: | Line 19: | ||
val = document["query"][quest.label + "." + 2].value; | val = document["query"][quest.label + "." + 2].value; | ||
if (val.length > 0) | if (val.length > 0) | ||
valid = | valid = validateEmail(val); | ||
} | } | ||
if (!valid) | if (!valid) |
Revision as of 02:38, 3 March 2009
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
var normalQuestionCheck = questioncheck;
function extendedQuestionCheck()
{
var valid = normalQuestionCheck();
if (valid)
{
var val;
//The value below is the index value of the sub question where your e-mail question is asked.
//In this case we use the sub question has index 2
val = document["query"][quest.label + "." + 2].value;
if (val.length > 0)
valid = validateEmail(val);
}
if (!valid)
{
alert('Wrong email address format');
return false;
}
return true;
}