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 user must have to input always 2 digit numbers.
You may use “regex” command in constraint column.
I can use it, but the factor is “0”. By this procedure ‘1’ is taken. But I need ‘01’ will be taken, not single “1”. And data type must be 'integer"
Hi @tanzilhuda,
Backing up with what @bernieseville have said you could do the same as shown in the image below:
In the survey sheet of the xlsform:
Note: With this expression you will not be able to enter 00, hence integer between 01 to 99 are only accepted.
Reference xlsform:
Regex_Constraint.xlsx (10.0 KB)
GOOD DAY!
It’s working perfectly. Thanks Thanks Thanks a lot @Kal_Lam. It’s only you who give me the awesome and perfect answer. Really, you are awesome.
Gracias @Kal_Lam por la ayuda, me sirvió de mucho tu respuesta y pude solucionarlo. Miles de gracias amigo. Saludos a la distancia.
I am facing a problem. If I want to limit the range from 01 to 48, I am using regex(., '^[01-48]{2}$') and (. >= 01)
then 09, 19, 29, 39 is restricted to write. So I can write 01 to 48 without any restriction?
Welcome back to the community, @tanzilhuda! Try using this constraint and it should work …
regex(., '^(0[1-9]|[1-3][0-9]|4[0-8])$')
survey sheet:
Updated XLSForm:
Regex_Constraint.xlsx (10.1 KB)
@Kal_Lam Really you are extraordinary. Billion of thanks.
Note, be careful with regex’s - they may not actually do what they appear! This regex
^[01-99]{2}$
will actually match any single character containing (ie the '[...]'
bit) 0, 1-9, or 9, and repeated twice (!):
So the regex itself is not actually matching a range of numbers between “01” and “99” (!), which is probably what it might immediately look like (!). Fortunately, by virtue of the fact of the ‘{2}’ suffix means that it excludes a single digit, or *three+ digits, and the subsequent “...and (.>=0)
” fortunately will exclude the unwanted “00
”.
That is, a regex('^[0-9]{2}'$
is probably more indicative of what check the regex is actually performing, ie always requiring 2 digits (between 0 and 9), with the same “...and (.>=0)
” to then ensure “00
” (converted to an integer) is also excluded.
Regex’s are notoriously tricky to interpret correctly and get right, and there’s always a chance of false positive (or worse, false negatives!) if you get 'em wrong. So I always double check them with a dedicated tool; I happen to like https://regex101.com/ because it gives me a English translation of what its actually doing.