How to use the same regex value multiple times within a survey form?

Dear community.
This is my first post. Thanks a lot for your very helpful tips.

I want to set up phone numbers limited to 9 digits with the following condition:

  • The first digit is 7

  • The second digit is either 0 or 5, or 6, or 7, or 8

  • The seven last digits can be any digit between 0 and 9

Because I want to you use this format in many questions I created a binding question named “phone” (of type ‘calculation’) with the following expression ‘[1]{1}[05678]{1}[0-9]{7}$’ The plan is to used it later like this : regex(.,${phone}) in several other questions in my form.

Unfortunately, when I test my file on this website ODK - XLSForm Online I get the following error :

Error: ODK Validate Errors:

XForm is invalid. See above for the errors.
: Invalid calculate for the bind attached to “${phone}” : Couldn’t understand the expression starting at this point: ͎[2]{1}[05678]{… in expression [3]{1}[05678]{1}[0-9]{7}$’

The following files failed validation:
${MAMII_baseline_SN} 04-03-2021_essai.xml

Result: Invalid

Please, would you mind telling me what is wrong ?


  1. 7 ↩︎

  2. 7 ↩︎

  3. 7 ↩︎

Welcome to the community, @ohebie! Your regex seems to be fine. Could you share your xlsform so that we could have a quick scan of how you have tried placing these constraints for other questions?

Thanks Kal_Lam
The xlsform is attached.

Thanks.

MAMII_baseline_SN 04-03-2021_essai.xls (293 KB)

Well in this case you could do it as outlined in the image shared below:

In the survey tab of your xlsform:

Data entry screen as seen in Enketo:

Reference xlsform:

Using a regex value multiple times.xls (41.5 KB)

1 Like

Thanks a lot Kal_Lam. It works.
The error message disappeared.

1 Like