Welcome to the LimeSurvey Community Forum

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

Some validation help

  • djarnold01
  • djarnold01's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 10 months ago - 8 years 10 months ago #120538 by djarnold01
Some validation help was created by djarnold01
Hello!

I need help with validation in my survey.

I use the "question by question mode" to show the survey

In one of the questions I have a multiple short free text and I need to validate some subquestions like email, phone number (only numbers), etc.. I found this code in the forum
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function () {
 
    var emailExp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
 
    // Interrupt the submit function
    $('form#limesurvey').submit(function () {
      // Override the built-in "disable navigation buttons" feature
      $('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
      var email = $("#answer31822X121X22232");
      var flag = emailExp.test(email.val());
 
      if (flag || email == '') {
        return true;
      } else {
        alert ('The email is invalid!');
        return false;
      }
    });
  });
</script>


The validation works great but the navigation buttons still inactive and I can´t move to the next question even the email field is correct.



The next question is...
I have a question with "multiple choice with comments" and "other option" so the question is "select only the items you have" and the subquestions are pencil, pen, eraser.
In the commet box of each subquestion the imput is only numbers (number of pencils, pens, erasers have). In other option can put other object and the total you have.
I need to sum all the numbers entered in the selected choices to get a total of 100 and validate when the total isn't 100.


Thanks and sorry for my bad english... is not my language
Last edit: 8 years 10 months ago by djarnold01.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #120552 by tpartner
Replied by tpartner on topic Some validation help
1) Try changing this:
Code:
$('form#limesurvey').submit(function () {
To this:
Code:
$('#movenextbtn, #movesubmitbtn').bind('click', function () {


2) I don't see a way to do that if you allow text and numerics in "Other"

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: djarnold01
The topic has been locked.
  • djarnold01
  • djarnold01's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 10 months ago - 8 years 10 months ago #120562 by djarnold01
Replied by djarnold01 on topic Some validation help
Thak you!!

So there is no way to do that in this type of question, right?

How about another type of question?

Or sum removing the "other" option. How it could be?
Last edit: 8 years 10 months ago by djarnold01.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #120594 by DenisChenu
Replied by DenisChenu on topic Some validation help
Hi,

For #1, why don't use em_validation_sq manual.limesurvey.org/Question_type_-_Mu...8em_validation_sq.29

For your example:
Code:
is_empty(QCODE_EMAIL.NAOK) or regexMatch("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/",QCODE_EMAIL.NAOK)

For multiple choice with comments:
For example with SQ001, SQ002 and SQ003:
In em_validation_q manual.limesurvey.org/Question_type_-_Mu...28em_validation_q.29
Code:
is_int(QCODE_SQ001comment.NAOK) and is_int(QCODE_SQ002comment.NAOK) and is_int(QCODE_SQ003comment.NAOK) and is_int(QCODE_othercomment.NAOK)
and
sum(QCODE_SQ001comment.NAOK,QCODE_SQ002comment.NAOK,QCODE_SQ003comment.NAOK,QCODE_othercomment.NAOK)==100

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: djarnold01
The topic has been locked.
  • djarnold01
  • djarnold01's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 10 months ago #120600 by djarnold01
Replied by djarnold01 on topic Some validation help
Thanks again!

#1 works great

#2 But, if only I select 2 of the 4 subquestions and the selections sum 100, this validation needs to put numbers in all subquestions... I tried changing the validation equation with no lucky.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago - 8 years 10 months ago #120605 by DenisChenu
Replied by DenisChenu on topic Some validation help
Hi
Code:
(is_int(QCODE_SQ001comment.NAOK) or is_empty(QCODE_SQ001comment.NAOK))
and 
(is_int(QCODE_SQ002comment.NAOK) or is_empty(QCODE_SQ002comment.NAOK))
and
(is_int(QCODE_SQ003comment.NAOK) or is_empty(QCODE_SQ003comment.NAOK))
and
(is_int(QCODE_othercomment.NAOK) or is_empty(QCODE_othercomment.NAOK))
and
sum(QCODE_SQ001comment.NAOK,QCODE_SQ002comment.NAOK,QCODE_SQ003comment.NAOK,QCODE_othercomment.NAOK)==100

Look at Expression Manager manual for more example and function.

PS: maybe you can try : sum(self.sq_comment) for example.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 8 years 10 months ago by DenisChenu.
The following user(s) said Thank You: djarnold01
The topic has been locked.
  • djarnold01
  • djarnold01's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 10 months ago #120609 by djarnold01
Replied by djarnold01 on topic Some validation help
Now it works!!

Thank you all for the support

I will donate for this great software
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose