Welcome to the LimeSurvey Community Forum

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

Numeric input question - Range Min-Max + Other values

  • eloner
  • eloner's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 1 month ago #130111 by eloner
Hello,
I use LS Versione 2.06+ Build 151215.
I am trying to add a question like this:

Q1. What is your net monthly income?
€ _ _ _ _ (999998 DK/NA)

Note that I have a range of 1-9999 for the income that can be easily assigned using Min and Max value in Advanced settings, and another value (999998), external to the range for the Don't Know/No answer.
I am asking if is there a way to set up a range of values in a numerical question so that a range of (n1-n2) + n3; n4; ... is accepted (where n3 and n4 are separate external values for Dont'know and No answer i.e., say 999998 and 999999).
In the case of a single value external to the range a possible solution would be to manage the 999998 option as the "Other" option, but numerical input question don't allow for such a possibility.
So... any suggestion is welcome!
Kind regards,
Elo
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #130120 by holch
I think your only chance is doing this via regex.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: eloner
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago - 8 years 1 month ago #130132 by tpartner
Yes, you could use this for the Question validation equation. For clarification, this basically says:
- 1-9 followed by 0-3 instances of 0-9
OR
- 5 9s followed by either 8 or 9
Code:
regexMatch('/^([1-9][0-9]{0,3}|9{5}[8-9])$/', self)

And something like this for the Question validation tip:
Code:
{if(is_empty(self) || regexMatch('/^([1-9][0-9]{0,3}|9{5}[8-9])$/', self), '', 'Error: Please enter a number between 1 and 9999 or 999998 or 999999')}

Sample survey attached:

File Attachment:

File Name: limesurvey...4359.lss
File Size:12 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 1 month ago by tpartner.
The following user(s) said Thank You: eloner, delarammahdaviii
The topic has been locked.
  • eloner
  • eloner's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 1 month ago #130134 by eloner
Thank you Holch and thank you Tpartner!
It works perfectly!
And given Q717 as question code, by using a simple expression I was able to set-up the range in this way:
(Q717 >= 1) && ((Q717 <= 9999) or (Q717 == 999998))) (--> Question Validation)

Cheers,
Elo
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose