Restrict string data type for serial number

#1

Hello everyone

I've just embarked on my first ODK questionnaire and am slowly getting the grips on regex validation codes.
So far, I managed to create some simple regex codes, however, with the one for my beneficiary serial number I seem to be stuck.

Basically my beneficiary serial number consists of 5 building blocks that the interviewer has to create:
[year][beneficiary category][first letter of the name of the community][first three letters of the beneficiary's first name][start time of the interview]

for example: 2019JEKNIN1011

In order to avoid typing errors, I would like to "guide" the interviewers in the sense, that they only have the necessary letters or number available for each building block.

For this I have come up with this regex code:
regex(.,'^2019[EJMOP][BDFGKRS]{1}[A-Z]{3}[0-9]{4}$')

Unfortunately it doesn't work and I can't find out why. Is it the fact tat I am restricting it for only certain letters? And if so, what do I have to change for it to work?

I would greatly appreciate your help with my validation code.

Thanks!

PS: I am using Windows 10, Firefox to create the questionnaire and KoBo Collect Version v.1.14.0a to test it.

#2

Is your beneficiary category 1 letter (as in your regex) or 2 (as it might appear to be in your example)?

#3

I have the following beneficiary categories:
JE
PME
PEP
OP

this is why I actually didn't want to limit the letters for the category building block.
but it looks like I did?

PS: sorry, I didn't explain my example:
2019JEKNIN1011
2019[year]JE[beneficiary category]K[first letter of the community]NIN[first three letters of first name]1011[start time of interview]

#4

Then instead of [EJMOP] you’ll need to explicitly list the 4 categories; try this instead :

(JE|PME|PEP|OP)

And that’s a vertical bar ‘|’ not a capitol i

#5

Thank you for your help.

So I entered the following regex code:
regex(.,'^2019[JE|PME|PEP|OP][BDFGKRS]{1}[A-Z]{3}[0-9]{4}$')

Unfortunately, in Kobo Collect it doesn't work.
It doesn't let me pass on to the next question if I enter my example:
2019JEKNIN1011

#6

I think you should be using (JE|PME|PEP|OP) instead of [JE|PME|PEP|OP]:

Corrected regex:
^2019(JE|PME|PEP|OP)[BDFGKRS]{1}[A-Z]{3}[0-9]{4}$

I have tried above here: https://regex101.com/r/6SUW1M/1

Hope this would help!

#7

yessss, it worked!
thaaaaanks!

#8

Correct, there is a significant difference between the () operation and [] operation. See https://www.rexegg.com/regex-quickstart.html