Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

regular expression issue

  • first
  • first's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
9 years 1 month ago #116526 by first
regular expression issue was created by first
HI , Need urgent help..

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;
  }
});

Survey Designer and Programmer
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 1 month ago #116531 by tpartner
Replied by tpartner on topic regular expression issue
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.
The following user(s) said Thank You: first
The topic has been locked.
  • first
  • first's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
9 years 1 month ago #116532 by first
Replied by first on topic regular expression issue
thank you TJ , you are always very helpful..:)

Survey Designer and Programmer
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
9 years 1 month ago #116635 by Mazi
Replied by Mazi on topic regular expression issue
The best approach to validate email addresses at Limesurvey is using Limesurvey's expression manager.
This is explained at this blog post: www.limesurvey-consulting.com/how-to-val...esses-at-limesurvey/

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The following user(s) said Thank You: first
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose