Multiple choice with comments (numbers only)

More
3 months 2 weeks ago #169633 by krosser
krosser created the topic: Multiple choice with comments (numbers only)
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'm using the latest LS 3.14 hosted on LS servers, not installed locally.
Attachments:

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago #169648 by krosser
krosser replied the 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"?

I'm using the latest LS 3.14 hosted on LS servers, not installed locally.
Attachments:

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago - 3 months 2 weeks ago #169680 by krosser
krosser replied the 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.

I'm using the latest LS 3.14 hosted on LS servers, not installed locally.
Last Edit: 3 months 2 weeks ago by krosser.

Please Log in or Create an account to join the conversation.

More
3 months 1 week ago #169685 by krosser
krosser replied the 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:
(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:
{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.14 hosted on LS servers, not installed locally.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!