Limit the integer and decimal value

HI

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)

Could someone help me on this

Thanks

Hi @Giri
can't you just use integer and decimal widgets and add constraint like .>0 and .<1000? If you use regex i guess you used a text widget why?

Hi,

Thanks.. Yes I used decimal and limited the values .<1000.
But I would like to limit the decimal values to 2 (0.01, 0.23,999.99)

We don't want to include 998.099 , 12.2324 etc...

Thanks

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.

1 Like

Yeah @noel_cartong is right and the function he mentioned is here https://docs.getodk.org/form-operators-functions/#number-handling

try this:

regex(., '^[0-9]+(\.[0-9]{1,2})?$')

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...].

1 Like