Toggle menu
862
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Force email address: Difference between revisions

From Catglobe Wiki
Phongha (talk | contribs)
Line 28: Line 28:
return true;
return true;
}
}
questioncheck = extendedQuestionCheck;
</source>
</source>

Revision as of 16: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

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;
}
questioncheck = extendedQuestionCheck;