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
Phongha (talk | contribs)
Cg van (talk | contribs)
No edit summary
Line 1: Line 1:
== Challenge ==  
== Force email address  ==
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 ==
You want the respondent to write an e-mail address.The script needs to validate if a string input is in email address format
<br>
 
[[Image:ValidateEmail.JPG]]
In order to check email address.
<br>
 
== Code ==
As a questionnaire creator
<source lang="javascript" line="1">
 
I want to validate if a string input is in email address format when the respondent writes an e-mail address.
 
'''Example'''
 
[[Image:ValidateEmail.JPG]]  
 
=== Code ===
 
<source lang="javascript">
var normalQuestionCheck = questioncheck;
var normalQuestionCheck = questioncheck;
function extendedQuestionCheck()
function extendedQuestionCheck()
Line 29: Line 37:
}
}
questioncheck = extendedQuestionCheck;
questioncheck = extendedQuestionCheck;
</source>
</source>  
 
=== Source  ===
 
Questionnaire Resource Id on cg site: 159730

Revision as of 08:55, 12 January 2012

Force email address

You want the respondent to write an e-mail address.The script needs to validate if a string input is in email address format

In order to check email address.

As a questionnaire creator

I want to validate if a string input is in email address format when the respondent writes an e-mail address.

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;

Source

Questionnaire Resource Id on cg site: 159730