How can I make a limit to the ‘integer’ data type?

My limit will be 01-99. No one can enter ‘1’. The user has to input ‘01’. That means in the integer (Number) data types users must have to input always 2 digit numbers.

2%20digit

Thanks in Advanced

Hi @TanzilHuda

you need to use regex something like just 0[1-9]|[1-9][0-9] maybe?

Thanks, @Grzesiek2010, I have tried just like your suggestion. But it's not working. Would you show me the exact code?
regularexpre

Hmmm I'm not an regex expert I just tested it using an online tool like https://regexr.com/ and it was fine.

It works on string data type. But not working on 'numeric' data type

Hi @TanzilHuda

01 is technically not an integer, but a string.

I suggest you use the text data type, setting the constraint="regex(.,'^[0-9]{2}$')"
You can also select appearance="numbers" to ensure the right keyboard is shown to the enumerators.

Reference: https://docs.opendatakit.org/form-regex/#tips-on-using-regular-expressions

I hope this helps!

Best,
Andrea

4 Likes

Unfortunately, this permits "00", whereas the requirement was 01-99 [D'oh! :slight_smile: ] This seemingly minor nit makes a solution rather messy...

Have a play around (eg here) with this regex instead:

regex(.'^(?!00)[0-9]{2}$')


  1. 0-9 ↩︎

1 Like

Thanks everyone. I got the answer. It is: