Welcome to the LimeSurvey Community Forum

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

Multiple choice with comments (numbers only)

  • Minh1987
  • Minh1987's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 days 1 hour ago - 2 days 1 hour ago #269864 by Minh1987
Hi

I have the same question with the previous topic:  forums.limesurvey.org/forum/can-i-do-thi...omments-numbers-only
However, his code did not work for me. I copied the codes and pasted in the Question validation equation and Question validation tip although I think validation tip makes non-sense.
I have 20 sub questions from SQ001 to SQ020, and respondents should choose 3 out of 20 and fill the number respectively. The number is expected from 1 to less than 100.

Could you please tell me what I should do? Thank you so much in advance.
Last edit: 2 days 1 hour ago by Minh1987.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 days 41 minutes ago #269865 by Joffm
The shown code is fine and works.
Of course you have to adapt it to your needs.
But as long as you don't show what exactly YOU did, it's difficult to find the issue on your side.

But the validation equation is rather straightforward:
Either the comment of the subquestion is empty OR (it is greater than 0 AND it is less or equal than 100)
And this for rach subquestion.

Or you use the function "regexMatch" with the suitable parameter.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Minh1987
  • Minh1987's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 days 18 minutes ago - 2 days ago #269866 by Minh1987
Replied by Minh1987 on topic Multiple choice with comments (numbers only)
Could you please help me to see where I was wrong?
Also, how to hide the tip to make the respondents not confused. I don't know why but all the lengthy validation tip appear in the screen.. Maybe I was wrong somewhere.
Last edit: 2 days ago by Minh1987.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 day 8 hours ago - 1 day 8 hours ago #269868 by Joffm
Hi,
1.  (is_empty(SQ001.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', SQ001.NAOK))
a. This is not a correct QCODE.
b. You do not test the comment box, but the checkbox
Please read the manual
[url] www.limesurvey.org/manual/ExpressionScri...code_variable_naming [/url]
And it's always a good advice to activate the survey and have a look at the response table. Here you see how you access all variables.

2. (is_empty(SQ001.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', SQ001.NAOK))
a, The regexMatch will allow numbers up to 99999.
Use a regex tester like [url] regex101.com/ [/url] to generate it.
b. If you use a correct regular expression you do not need to test for "is_empty"
3. Your validation tip is not correct.
You test each subquestion separately.
Either you should test all in one equation to show only one error message like "Only numbers between 1 and 100 are allowed"
{if(!regexMatch('/^([1-9][0-9]?[0]?)?$/',Q01_SQ001comment) OR !regexMatch('/^([1-9][0-9]?[0]?)?$/',Q01_SQ002comment) OR !regexMatch('/^([1-9][0-9]?[0]?)?$/',Q01_SQ003comment) OR ...,'Please, only numbers...','')}
Or you test the subquestions one by one, in a nested IF function
{if(!regexMatch('/^([1-9][0-9]?[0]?)?$/',Q01_SQ001comment),'Please enter only numbers in '+Q01_SQ001.question, if( !regexMatch('/^([1-9][0-9]?[0]?)?$/',Q01_SQ002comment),'Please enter only numbers in '+Q01_SQ002.question,if(!regexMatch('/^([1-9][0-9]?[0]?)?$/',Q01_SQ003comment), 'Please enter only numbers in '+Q01_SQ003.question,...,''))))))))))}

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 day 8 hours ago by Joffm.
The following user(s) said Thank You: Minh1987

Please Log in to join the conversation.

  • Minh1987
  • Minh1987's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 day 6 hours ago #269871 by Minh1987
Replied by Minh1987 on topic Multiple choice with comments (numbers only)
Thank you so so much for pointing out my mistakes! It works already. So great...

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose