- Posts: 222
- Thank you received: 10
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Multiple choice with comments (numbers only)
- krosser
- Topic Author
- Offline
- Elite Member
Less
More
5 years 9 months ago #169633
by krosser
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Multiple choice with comments (numbers only) was created by krosser
Hey guys,
I need to make it possible to enter numbers only in comment boxes in a multiple choice question. I have tried to use number validation from the manual in the Question validation equation field, but it hasn't worked.
Number validation
Numbers from 1 to 99999
/^([1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9])$/
/^[1-9][0-9]{0,4}$/ does the same as above but should run a little faster
Any ideas on what code should be used?
I need to make it possible to enter numbers only in comment boxes in a multiple choice question. I have tried to use number validation from the manual in the Question validation equation field, but it hasn't worked.
Number validation
Numbers from 1 to 99999
/^([1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9])$/
/^[1-9][0-9]{0,4}$/ does the same as above but should run a little faster
Any ideas on what code should be used?
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Attachments:
The topic has been locked.
- krosser
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 9 months ago #169648
by krosser
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Multiple choice with comments (numbers only)
Okay, so I've figured out that it should be a much more sophisticated code in the validation equation and also in the tip. But I can't figure out the correct syntax for the validation tip.
For example, for just the first answer option:
(is_empty(Expertise_SQ001comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ001comment.NAOK))
{if((is_empty(Expertise_SQ001comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ001comment.NAOK)), ', 'test message...')}
And I get this
Any ideas guys what should be corrected in the validation tip to make it visible as only "test message"?
For example, for just the first answer option:
(is_empty(Expertise_SQ001comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ001comment.NAOK))
{if((is_empty(Expertise_SQ001comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ001comment.NAOK)), ', 'test message...')}
And I get this
Any ideas guys what should be corrected in the validation tip to make it visible as only "test message"?
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Attachments:
The topic has been locked.
- krosser
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 9 months ago - 5 years 9 months ago #169680
by krosser
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Multiple choice with comments (numbers only)
Well, I've managed to fix it through trial and error.. So the code should be like this
{if(is_empty(Expertise_SQ001comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ001comment.NAOK), '' , 'Only numbers are allowed')}
But it's only for the first comment box. I haven't figured out the syntax for applying it to other comment boxes yet.
{if(is_empty(Expertise_SQ001comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ001comment.NAOK), '' , 'Only numbers are allowed')}
But it's only for the first comment box. I haven't figured out the syntax for applying it to other comment boxes yet.
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Last edit: 5 years 9 months ago by krosser.
The topic has been locked.
- krosser
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 9 months ago #169685
by krosser
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Multiple choice with comments (numbers only)
Alright, so I've figured it out... and in case someone would need it, here's how I did it.
A screenshot from this example in the manual has helped.
It's basically copying the code for each row and changing subquestions' codes.
So in my case, for the Question validation equation:
and for the Question validation tip:
A screenshot from this example in the manual has helped.
It's basically copying the code for each row and changing subquestions' codes.
So in my case, for the Question validation equation:
Code:
(is_empty(Expertise_SQ001comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ001comment.NAOK)) and (is_empty(Expertise_SQ002comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ002comment.NAOK)) and (is_empty(Expertise_SQ003comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ003comment.NAOK)) and (is_empty(Expertise_othercomment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_othercomment.NAOK))
and for the Question validation tip:
Code:
{if(is_empty(Expertise_SQ001comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ001comment.NAOK), '' , 'Only numbers are allowed')} {if(is_empty(Expertise_SQ002comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ002comment.NAOK), '' , 'Only numbers are allowed')} {if(is_empty(Expertise_SQ003comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_SQ003comment.NAOK), '' , 'Only numbers are allowed')} {if(is_empty(Expertise_othercomment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', Expertise_othercomment.NAOK), '' , 'Only numbers are allowed')}
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.