Constraints not functional in collect

Helo family
Could someone help me understand why my constraint syntaxes (below) are not functional in collect despite form being validated by Enketo;

regex(., ‘^[0-9]{3}$’) - to limit age to have a maximum of 3 characters.

regex(., ‘[A-Za-z0-9._%+-]{10,15}’) - to allow alphanumeric characters of upto 15 characters

Will be grateful


Your regex's are syntactically valid, but probably not doing what you intend. Try this:

regex(., ‘^[0-9]{1,3}$’)
regex(., ‘[A-Za-z0-9._%+-]{1,15}’)

Specifically, the {} qualifier with a single value matches exactly (and only) that number of characters, whereas you appear to want "maximum of..." / "up to..."

Note, because you dont include a start/end marker in your second regex, it'll successfully match the string "123()###ABC", because - despite the supposedly invalid '(' and "#' characters - it'll still find matching substrings (if that's what you want...)

You can also pre-check your regex's using an online tool, eg regex101

Thank you Gareth, tried it but successful.

Could you guide me on a simple contraint that can;

  1. limit age entry to just 15 - 24 years.

  2. Limit entry to allow alphanumeric upto 15 characters.

Besides could it be my ODK version or OS not accepting such contraints?


regex(., ‘^[0-9A-Za-z]{1,15}$’)

A really good way to learn regex's is by looking at examples to see how to accomplish various things.

This doesn't need to be a regex, and is more easily accomplished using a simple boolean expression:

constraint='(. >= 15) and (. <= 24)'


thank you Gareth