regex test (emailPat) in below code is working fine when I am injecting code in browser through browser console but it doesnt work after placing it in LS question text. Is there any special way of using regular expression in LS?
Code:
var $emailBoxes = $('#answer559779X556X128541_a,#answer559779X556X128542_a');
var emailPat = /^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/
$('#movenextbtn').on('click',function(){
var errorState = false;
$emailBoxes.each(function(){
var tempEmailInput = $.trim($(this).val());
if(tempEmailInput != '' && emailPat.test(tempEmailInput) == false){ //Input is not empty and Do not pass email validation test
$(this).css('background-color','red');
$('span.questionhelp:first').text('Please enter valid email id').css('color','red');
errorState = true;
}
});
if(errorState){
return false;
}
});
With the advent of Expression Manager, you cannot have curly braces in regexes in the question source (I know, I know, don't get me started on that again).
Try defining the emailPat var in template.js instead of in your question.
Cheers,
Tony Partner Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Best regards/Beste Grüße,
Dr. Marcel Minke
survey-consulting.com
offlinesurveys.com
Feel free to contact me by email for professional LimeSurvey support!