Hello,
I am using a "decimal" question type and want to restrict the answers to a certain range and to a specific format:
I have tried various options, but none was completely satisfying.
Constraint
With a constraint like ". >= 0 and . <= 14" it is not possible to restrict the number of decimal places.
Input Mask
The input mask enforces the answer to exactly match the mask, i. e. the value 1 for the input mask 99.99 would require the answer 01.00, otherwise the answer fails validation.
Regex
I cannot think of any regular expression that fulfills all above mentioned restrictions since it has to do two things: Set limits to the allowed values (0 <= x <= 14) and also format the answer correctly. Moreover, I have the impression that in Survey123 regular expressions don't work correctly when applied to a decimal question.
So, what I need is a combination of constraint and
Does anyone have an idea how to deal with this?
Are there any enhancements planned for a future version of Survey123?
Right now, is it possible to combine a value limiting constraint and a regular expression (I was not successful with my tests)?
Thank you very much, best regards,
Jürgen
Hi Jürgen,
To test for a maximum of 2 decimal places, I would multiply the number by 100 and compare it against the integer of that number * 100:
. * 100 = int(. * 100)
This can be added on to your current constraint.
As for the requirement that there be no leading 0, why is that relevant in the entering of a number? 0.04 and .04 are equivalent numbers.
Hi James,
Thanks for the hint, again pretty simple.
As for the leading zero: The integer and decimal question types also allow e. g. 001 or 0003.12 respectively. This can be confusing and isn't, let's say, good style. But this is only cosmetic, not an error.
Best regards,
Jürgen