Toggle menu
876
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle preferences menu
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
Line 23: Line 23:
var valid = normalQuestionCheck();
var valid = normalQuestionCheck();
   if (valid)  
   if (valid)  
{
{
        // val = email i form
              var val;
                var val;
//The value below is the index value of the sub question where your e-mail question is asked.
//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  
//In this case we use the sub question has index 2  
Line 31: Line 30:
            if (val.length > 0)
            if (val.length > 0)
valid = isEmail(val);               
valid = isEmail(val);               
}
}
if (!valid)  
if (!valid)  
{  
{  

Revision as of 09:39, 2 March 2009

Challenge

You want the respondent to write an e-mail address.

Example



Code

//function to validate if an email address 
function isEmail(str)
{
	var emailFormat = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?$/i;
	var emailAdress = str;
	if(emailAdress.search(emailFormat)==-1)
		return false;
	else 
		return true;
}

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 = isEmail(val);               
	 }
	 if (!valid) 
	 { 
 	        alert('Wrong email address format');
                return false;
         }
	 return true;
}