Some validation help

More
3 years 5 months ago - 3 years 5 months ago #120538 by djarnold01
djarnold01 created the topic: Some validation help
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
<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: 3 years 5 months ago by djarnold01.

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #120552 by tpartner
tpartner replied the topic: Some validation help
1) Try changing this:
$('form#limesurvey').submit(function () {
To this:
$('#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

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #120562 by djarnold01
djarnold01 replied the 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: 3 years 5 months ago by djarnold01.

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #120594 by DenisChenu
DenisChenu replied the 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:
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
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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: djarnold01

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #120600 by djarnold01
djarnold01 replied the 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.

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #120605 by DenisChenu
DenisChenu replied the topic: Some validation help
Hi
(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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 3 years 5 months ago by DenisChenu.
The following user(s) said Thank You: djarnold01

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #120609 by djarnold01
djarnold01 replied the topic: Some validation help
Now it works!!

Thank you all for the support

I will donate for this great software

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!