Force email address

From Catglobe Wiki
Revision as of 04:38, 3 March 2009 by Catglobe (talk | contribs) (Code)
Jump to: navigation, search

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


ValidateEmail.JPG

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 }