Check out the LimeSurvey source code on GitHub!

Condition on Odd/Even Numbers?

More
5 years 9 months ago #60871 by piquadrat
Hello community,

I would like to set a condition based on a number entry of an earlier question. Thereby I want to base the condition whether the previous entry was an odd or even number.

Can anyone tell me, how I can implement this with RegEx?

I figured out that

Odd Numbers is "^\d*[13579]$" and Even Numbers is "^\d*[02468]$".

But how can I implement this in Limesurvey?

Thanks a lot for your help!

P.s.: I'm using Limesurvey Version 1.90+ Build 9642.

Please Log in to join the conversation.

More
5 years 9 months ago #60884 by tpartner
In the conditions interface, you need to set the comparison operator to "Regular expression" - docs.limesurvey.org/Setting+conditions&s..._comparison_operator .


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: piquadrat

Please Log in to join the conversation.

More
5 years 9 months ago #60887 by piquadrat
Thanks a lot - it turned out that the problem is, that the RegEx Code only works on numbers between 0-9. Do you have any idea how it can be changed to be used with numbers up to 4 digits (e.g. 1995)?

Please Log in to join the conversation.

More
5 years 9 months ago #60889 by tpartner
Try this to find if the last digit in the string is odd or even:

Even:
[02468]$

Odd:
[13579]$

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: piquadrat

Please Log in to join the conversation.

More
5 years 9 months ago #60893 by piquadrat
Thanks a lot - that helped me out!

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form