I am working on a sample xls form. where I have a limited integer (1-999) can be entered.
I tried this using regex(.,'^[0-9]{1}$') or regex(.,'^[0-9]{2}$') or regex(.,'^[0-9]{3}$') and it works fine.
But I also wanted to add a decimal to this. where as I stick on the value limiitation (0.01 to 999.99)
instead of limiting the number of decimal places you could accept any number of decimal places and then round the result in a calculate question in order to keep your data exports tidy for easy analysis.
alternatively you could write a more complicated regex which forces the response to have 2 decimal places but I am not sure I see why that would be better.
Note, the decimal point is optional, but if you include a decimal point then you must include at least one or two decimal digits [your problem description wasn't specific about this, so I made an assumption...].
I've solve this by using the module function, module functions works wtih integer so you'll have to multiply the decimal input and it gets truncated as an integer. In this case to get 2 decimal numbers use de constraint:
((.*1000 mod 10)=0)
lets see how this works with different inputs:
4
4*1000=4000
(4000 mod 10)=0 valid
4.01
4.01*1000=4010
(4010 mod 10)=0 valid
4.1
4.1*1000=4100
(4100 mod10)=0 valid
4.123
4.123*1000=4123
(4123 mod 10)=3 not valid
I needed to accept only multiples of .05 so I used
((.*1000 mod 50)=0)