Alphanumeric constraint for matching pre-post surveys

I’m trying to write a constraint that would enable respondents to enter a code we send them via email in order to match their post survey with a pre survey.

An example of the 18-digit code is:
AMPS-HK-2020-0710-1233

The first four digits need to be alphanumeric, the next 2 uppercase letters, the rest numbers.

I’ve progressed this far based on regex codes for but it doesn’t seem to work. I keep getting the constraint message.

regex(., ’^[a-zA-Z0-9]{4}[-][a-zA-Z]{2}[-][0-9]{4}[-][0-9]{4}[-][0-9]{4})$’)

This will be a survey on Enketo and I’ve been consulting this page: https://support.kobotoolbox.org/restrict_responses.html)

Thank you.

Could you please try the below regex
regex(.,’[2]{4}[-][A-Z]{2}[-][0-9]{4}[-][0-9]{4}[-][0-9]{4}$’)

Please note the second point below


  1. a-zA-Z0-9 ↩︎

  2. A-Z ↩︎

1 Like

Hi @hek,

As an alternative you could also try these out:

regex(., ’^[A-Z]{4}-[A-Z]{2}-[0-9]{4}-[0-9]{4}-[0-9]{4}$)

or,

regex(., ’^[A-Z]{4}[-]{1}[A-Z]{2}[-]{1}[0-9]{4}[-]{1}[0-9]{4}[-]{1}[0-9]{4}$)

Have a great day!

1 Like

Thanks to @stephanealoo and @Kal_Lam
Here is the code that did what I needed - combo of both responses!
regex(., ‘^[A-Z0-9]{4}[-][A-Z]{2}[-][0-9]{4}[-][0-9]{4}[-][0-9]{4}$’)

Go Team!

2 Likes