Hi,
I am trying to do a regex constraint on a field of type "decimal".
The regex is the following: regex(.,'^[+-]?[0-9]{1,2}\.[05]$')
What this says is that i want a number to looks like this: 10.5 or 6.0 etc..
The problem is that the regex evaluate to false when i place a 0 at the decimal. It correctly evaluate to true if the decimal is a 5.
If I use a field of type "text" the regex correctly understand the decimal 0 or 5, so the regex expression is correct. It seems to be a problem with fields of type "decimal".
Is there anyway to solve this? Is it possible to parse the number to text before evaluating it with the regex?
EDIT:
Ok this regex seems to work: regex(.+"",'^[+-]?[0-9]{1,2}(\.[05]{1})?$')
But somehow both regex I used allow for 10. or 5. for exemple (a number without any decimal)
Solved! Go to Solution.
Hi Nicolas,
Just to be clear, you are trying to constrain values to either be whole numbers or whole and a half? It might be easier to have a mathematical constraint - one way is to multiply by 10 and then check for a remainder using modulo:
(.*10) mod 5 = 0
Hi Nicolas,
Just to be clear, you are trying to constrain values to either be whole numbers or whole and a half? It might be easier to have a mathematical constraint - one way is to multiply by 10 and then check for a remainder using modulo:
(.*10) mod 5 = 0
Hi James,
thank you for your support. Yes that is what I am trying to do.
I just tested your solution and it works fine (in the desktop survey viewer)! I might be able to drop all those regex call. I will simply make sure the number is lower then 100 and also do the modulo test you just sent me.
thank you