- Posts: 59
- Thank you received: 9
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
- Topic Author
- Offline
- Senior Member
Less
More
8 years 2 months ago #130111
by eloner
Numeric input question - Range Min-Max + Other values was created 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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11758
- Thank you received: 2753
8 years 2 months ago #130120
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Numeric input question - Range Min-Max + Other values
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
8 years 2 months ago - 8 years 2 months ago #130132
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Numeric input question - Range Min-Max + Other values
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
And something like this for the Question validation tip:
Sample survey attached:
- 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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 8 years 2 months ago by tpartner.
The following user(s) said Thank You: eloner, delarammahdaviii
The topic has been locked.
- eloner
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 59
- Thank you received: 9
8 years 2 months ago #130134
by eloner
Replied by eloner on topic Numeric input question - Range Min-Max + Other values
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
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.