Problem adding regex constraint using the application designer

Hi, I’m new to ODK and trying to add a regex expression to the constraint field of one survey questions.
I’ve tried the example on ‘Using regular expressions’ document on the odk website.

What is the problem? Please be detailed.
I’m getting an error on die ODK application designer when trying to convert the XLSX
when using the regex example in the in the documentation in the constraint field. The regex : regex(.,’^[a-zA-Z]{0,6}$’).
The converter gives the following error :
Error: Unexpected token . interpretting formula: regex(.,’^[a-zA-Z]{0,6}$’) on sheet: survey row: 21 column: constraint

What ODK tool and version are you using? And on what device and operating system version?
I’m using the following :
Windows 10 operating systerm
ODK Application Designer 2.1.0
ODK Aggregate v1.7.1 using Google App engine

What you have you tried to fix the problem?
I’ve tried chaning the regex to : regex(’.’,’^[a-zA-Z]{0,6}$’) in which case the xlsx converter successfully coverts the file
but when I try to complete the survey on the preview screen I get the following error when trying to complete the question with the regex.

Exception while evaluating constraint() expression. See console log.

And this is the error in the console log :

E/Exception ‘regex is not defined’ in user-defined expression: regex(’.’,’^[a-zA-Z]{0,6}$’) on survey row 21 column: constraint

Hi @Belzakura! Welcome to using ODK!

So one super confusing thing about ODK that I think is causing your troubles is that you are using app-designer, which is part of ODK2, but trying to apply directions from ODK1. There are two tool suites, ODK1 and ODK2, and they aren’t cross-compatible.

Here’s some info on choosing the right tool suite for you:

If ODK2 and app designer are what you want, then for the constraint, you’ll want to follow info here in ODK2 docs:

For example, in one of our surveys in 2018 we were collecting year of birth in variable q305_2. So we had a constraint:
(data(‘q305_2’) >= 1919 && data(‘q305_2’) <= 2018) || data(‘q305_2’) == 9998
and our message was:
Year {1919-2018, 9998 if don’t know}

Hope that helps!


Dear Caroline

Thank you very much for your reply. Is it possible to add a constraint in ODK2 to validate data that contains text and numbers? For example to check that a string value is in the following format : name_a1b2c3d4e5 ; name_g1y2h3u4j5 ; name_d8a9f6s5e4 etc.

Dear @Belzakura,

So in general constraints evaluate JavaScript expressions. If you can create a JavaScript expression to validate that string format, then yes, should be possible. I don’t know exactly how to do that for your particular combinations, but I definitely have done things like string length and such before, so expect it is possible if you dig through JavaScript operators to find the right ones.