Welcome to the LimeSurvey Community Forum

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

Question validation : multiple of a number

  • bferrie
  • bferrie's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 8 months ago #187377 by bferrie
Hi,

My question is a little specific.
In one of my survey, i ask participants to input a number of 6 characters wich is a multiple of 13. (The number is like 450013 or 790039, the two first characters are fixed, this number is gave to the participants on a paper).
I would like to make a validation to this question, if the number begin well by 45 or 79 and if the number is well a multiple of 13.
I didn't know how to do the expression in the validation field.

I use limesurvey 3.17.8 and vanilla theme.

Can you help me ?

Thanks.

bf
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #187383 by Joffm
Replied by Joffm on topic Question validation : multiple of a number
Hi,
you probably studied the demo surveys in the demo installation.
demo.limesurvey.org/admin/admin.php
In "Demo of em_validation_sq" you find a question called "Enter multiple of 5".

So take this validation - adapted to 13 - and add a validation to check if the value starts with 45 or 79, function "substr".
And remember, the first index of "substr" is "0".

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • bferrie
  • bferrie's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 8 months ago #187417 by bferrie
Replied by bferrie on topic Question validation : multiple of a number
Sincererly, thank you !
I'm ashamed of saying that i didn't know the demo installation. That's great.
I found in the manual that modulo-function is not supported and i have to use the floor function to do this, but i didn't know how. Finally, it wasn't so difficult.
Thank you too for the substr function, it works well.

My equation : (substr(this, 2,4) / 13) == floor(substr(this, 2,4)/13) && substr(this, 2,4) > 0 && (substr(this, 0,1) == 45 OR 79)
I added a function ">0" because if the participant enters 790000, it works, what i don't want to.

One thing i don't understand, what is the difference between "Subquestion validation equation" and "Question validation equation" ? My question type is short free text, so i think i have to use "Question validation equation", but i'm not sure.
Also, what is the "Validation" field in "general options" category of the question ? Is that different from the "Question validation equation" from the Logic category ?

Thanks for your help.

bf
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #187429 by DenisChenu
Replied by DenisChenu on topic Question validation : multiple of a number
In sub question : you can use this as a shortcut to current element.

For example `this > 3` in multi number : then each number must be up than 3.

There are a devlopement project to set the error input on the broken element only : github.com/LimeSurvey/LimeSurvey/blob/d2...ger_helper.php#L6787

But i think this sentence is here since 1.92 version … a long time TODO …

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 topic has been locked.
  • bferrie
  • bferrie's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 8 months ago - 4 years 8 months ago #187433 by bferrie
Replied by bferrie on topic Question validation : multiple of a number
Thank you for you explanation Denis.
Indeed, a long time !

So if i understand well, for a single numerical input, i can input the equation with "this" in "Question validation equation" as in "Subquestion validation equation", it doesn't make a difference, no ?

bf


Edit : i add "strlen(this) == 6" to my equation to force correct string length
so : strlen(this) == 5 && (substr(this, 2,4) / 13) == floor(substr(this, 2,4)/13) && substr(this, 2,4) > 0 && (substr(this, 0,1) == 45 OR 79)
Last edit: 4 years 8 months ago by bferrie.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #187478 by DenisChenu
Replied by DenisChenu on topic Question validation : multiple of a number

bferrie wrote: So if i understand well, for a single numerical input, i can input the equation with "this" in "Question validation equation" as in "Subquestion validation equation", it doesn't make a difference, no ?

If i don't make error this is related to subquestion only in Subquestion validation equation

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 topic has been locked.
  • bferrie
  • bferrie's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 8 months ago #187531 by bferrie
Replied by bferrie on topic Question validation : multiple of a number
Ok, thanks.
That's a bit complicated for me....

When i take the survey "Demo of em_validation_sq" that Joffm advised me, if i look the logic file, there is no difference (for me) between questions with Subquestion validation equation and others with Questions validation equation. The transcription of the equation "this/5 == floor(this/5)" seems to be the same.

I think i don't have the skills needed to fully understand that, but my problem is solved, the equation works in "Question validation equation", so thanks to you two.

bf
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose