Answer only X or ##.##

More
2 months 1 week ago #172146 by jimdavies
jimdavies created the topic: Answer only X or ##.##
Is it possible to force users to enter an answer as either an X or a two decimal number?



I had these settings to force an answer to be a two decimal number

Question validation equation: is_empty(self) OR regexMatch('/^[0-9]+(\.[0-9][0-9])$/',self)

Question validation tip: {if(is_empty(self) OR regexMatch('/^[0-9]+(\.[0-9][0-9])$/',self), "Enter number with two decimals points", "Enter number with TWO decimal points")}

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

More
2 months 1 week ago #172147 by Joffm
Joffm replied the topic: Answer only X or ##.##
Hi,
though I think this is not the best way, ... up to you.

Just extend the regular expression.
A lot of examples here:
http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3

E.g.
is_empty(self) OR regexMatch('/(^[0-9]+(\.[0-9][0-9])$)|(^X$)/',self)

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: jimdavies

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

More
2 months 1 week ago #172148 by jimdavies
jimdavies replied the topic: Answer only X or ##.##
Why is 100.00 not considered a valid value with this?

is_empty(self) OR regexMatch('/(^[0-9]+(\.[0-9][0-9])$)|(^X$)/',self)

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

More
2 months 1 week ago #172149 by jelo
jelo replied the topic: Answer only X or ##.##
Could be a bug in LimeSurvey. There is a regex done in Javascript and in PHP. Somestimes there is a bug in one or both regex-routines.
You should prepare a survey with the nonworking part and attach it here.
What version of LimeSurvey was used?

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

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

More
2 months 1 week ago #172150 by jimdavies
jimdavies replied the topic: Answer only X or ##.##
Here is the survey. It's on our test environment so no worries if it's used. It's the third to the last question where I have the validation that doesn't accept 100.00
surveys-staging.peoplescout.com/691893?lang=en

I'm on Version 2.58.0+170104

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

More
2 months 1 week ago - 2 months 1 week ago #172151 by Joffm
Joffm replied the topic: Answer only X or ##.##
Check again.

Here is the result:
Wrong:


Correct:


regexMatch('/(^[0-9]+(\.[0-9][0-9])$)|(^X$)/',self)
As you know the "+" means: the expression before can be repeated 1 to x times and is a synonym for {1,}.
So you could try this or - I think you enter percentages up to 100 - {1,3}, which means 1 to 3 repeats.

Joffm

BTW:
If you work with 2.58 there is a far better way to do this.
Use the plugin "checkboxfortext".
Here you can have one or two checkboxes below the textinput field e.g. "NA" and "DK"


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last Edit: 2 months 1 week ago by Joffm. Reason: wrong picture

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

More
2 months 1 week ago #172153 by jimdavies
jimdavies replied the topic: Answer only X or ##.##
That's weird that 100.00 worked for you. I had another user try and he got the same result as me. But if you put in 100.01 it would take it

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

More
2 months 1 week ago #172154 by Joffm
Joffm replied the topic: Answer only X or ##.##
No, it's because you didn't say that you use 2.58.
Of course my example was in 3.13.2


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

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

More
2 months 1 week ago #172155 by jimdavies
jimdavies replied the topic: Answer only X or ##.##
I mentioned the version up above. Is this a bug with the version I'm on?

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

More
2 months 1 week ago - 2 months 1 week ago #172158 by Joffm
Joffm replied the topic: Answer only X or ##.##
Hi, now I tested in Version 2.73.1+171220

is_empty(self) OR regexMatch('/(^[0-9]+(\.[0-9][0-9])$)|(^X$)/',self)


Wrong entries:



Correct entries:



I have not the least idea why there are problems in version 2.58

An here is a different approach:
array with some javascript. (entries are exclusive)


Joffm

Yes, you mentioned it.
But at that time I was already working on the example (not in the first post). I saw it after I submitted the post. ;)


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last Edit: 2 months 1 week ago by Joffm.

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!