Validate email specified as an open text of a single question

From Catglobe Wiki
Revision as of 04:01, 17 November 2009 by Catglobe (talk | contribs) (Created page with '==Challenge== In order to secure my questionnaire's input<br/> As a CGS writer <br/> I want to validate an email specified as an open text of a single question<br/> Example<br/> …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Challenge

In order to secure my questionnaire's input
As a CGS writer
I want to validate an email specified as an open text of a single question
Example
Validate email - semi open question.png

Solution

var qLabel = "Q1";
var openAnswerValue = 1;
var ErrorMessage_InvalidEmail = "Invalid email.";
   
var oldQuestionCheck = this.questioncheck;
questioncheck = function()
{
   if (!oldQuestionCheck())
   return false;
   
   var email = $("input[name='QUESTION." + qLabel + ".Open." + openAnswerValue +"']").val();
   
   if (!validateEmail(email))
   {
      ErrorMessages.getInstance().showErrorMessage(ErrorMessage_InvalidEmail);
      return false;
   }
   
   return true;
}