Welcome to the LimeSurvey Community Forum

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

Answer only X or ##.##

  • jimdavies
  • jimdavies's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 8 months ago #172146 by jimdavies
Answer only X or ##.## was created by jimdavies
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")}
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #172147 by Joffm
Replied by Joffm on 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:
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
The topic has been locked.
  • jimdavies
  • jimdavies's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 8 months ago #172148 by jimdavies
Replied by jimdavies on 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)
The topic has been locked.
More
5 years 8 months ago #172149 by jelo
Replied by jelo on 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?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • jimdavies
  • jimdavies's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 8 months ago #172150 by jimdavies
Replied by jimdavies on 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
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago - 5 years 8 months ago #172151 by Joffm
Replied by Joffm on 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
Last edit: 5 years 8 months ago by Joffm. Reason: wrong picture
The topic has been locked.
  • jimdavies
  • jimdavies's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 8 months ago #172153 by jimdavies
Replied by jimdavies on 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
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #172154 by Joffm
Replied by Joffm on 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
The topic has been locked.
  • jimdavies
  • jimdavies's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 8 months ago #172155 by jimdavies
Replied by jimdavies on topic Answer only X or ##.##
I mentioned the version up above. Is this a bug with the version I'm on?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago - 5 years 8 months ago #172158 by Joffm
Replied by Joffm on 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: 5 years 8 months ago by Joffm.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose