Validate email js

From Catglobe Wiki
Jump to: navigation, search

This solution will help you validate email

First create a text question, then add the below script to Javascript tab 2018-06-05 15-33-27.png

Question.bind('afterValidateQuestion', function(ev, question, state) {
   var invalidemail="Emailadressen er ikke korrekt. Ret venligst emailadressen";
   var email = question.attr('answer');
   if (!validateEmail(email))
      {
        question.attr('errorMessage', invalidemail);
        state.valid = false;
      }
});
window.validateEmail = function(emailAddress) {
  var pattern = new RegExp(/^([a-zA-Z0-9-_.]{1,128})@(\w+([-.]\w+)*\.\w+([-.]\w+)*)$/i);  
  return pattern.test(emailAddress);
};

2018-06-05 15-03-25.png