Re: how to constrain an ID to a range of alphanumeric characters

495 views
Skip to first unread message

Martijn van de Rijdt

unread,
Jan 5, 2015, 11:16:36 AM1/5/15
to zairen samsi, enketo...@googlegroups.com
Hi Zairen,

This question belongs in one of the forums (ODK, Formhub, Ona, KoBo, SurveyCTO, Enketo, whichever you are using). I'm cc-ing this to the Enketo forum. Make sure you make your title as descriptive as possible when you post a question like this.

The answer is to use a regular expression as constraint (see XLSForm.org for how to add a constraint). I think this will work: 

constraint="regex(., '^SIE(150[6-9]|15[1-9][0-9]|1[6-9][0-9][0-9]|2[0-9][0-9][0-9]|300[0-9]|3010)$')"

Maybe somebody can think of a better one. I like this tool to test regular expresssions: http://www.regexr.com/.

Cheers,
Martijn

---------- Forwarded message ----------
From: zairen samsi <[deleted]>
Date: Sun, Jan 4, 2015 at 10:35 PM
Subject: how to put constraints
To: sup...@enketo.org


Hi

I am Zairen. I am working on with my form right now and having some issue to put the constraints in the form.

Here it is, I want to put some id number with this range SIE1506 until SIE3010.

Could you help me on how to arrange the constraints so that when we enter the ID number will only at those range of number.

Thank you for your support.

Regards,
Zairen Samsi


-- 
Revolutionizing data collection since 2012.

Enketo    |    LinkedIn    |    GitHub    |    Twitter    |    Blog

Adam Dawoodjee

unread,
Feb 4, 2016, 11:01:39 AM2/4/16
to enketo-users, zaire...@gmail.com, sup...@enketo.org

Are there any limitations to Regular Expression constraints in KoBoToolbox/Enketo


Over the past 2 days I've dedicated my time to learning Regular Expressions (regex) from regexone.com and testing my expressions on the KoBo recommended regexr.com. I've significantly upped my skill.

Problem is I can write, test, and pass regex on regexr.com, but not all will pass within KoBo (enketo form preview) when I preview my forms even with properly formatted answers. A few tests have shown that:

1. For Numberical character "\d" equivalent to "[0-9]", inputs 0-9 do not pass on form preview, however the letter "d" will.
2. Any Whitespace "\s" does not work either with " ", maybe "s" will.

I have not tested for \w, and their opposites (\W, \S, \D, etc.)

This leads me to think that the Regex engine used in either the previews or maybe the rest of KoBo is different from regexr.com's. Otherwise the Regex engine has not been completely implemented.

I need to be able to pass input such as 123456/10/1, I've tried these:
- [0-9]{6}\/[0-9]{2}\/[0-9]
- \d{6}\/\d{2}\/\d

If anything it will work until [0-9]{6}\/[0-9]{2} = 123456/10, and no further.

I'll appreciate some help on this.

Martijn van de Rijdt

unread,
Feb 4, 2016, 12:31:37 PM2/4/16
to enketo-users, zaire...@gmail.com, sup...@enketo.org
Thanks a lot for this report, Adam. It has a technical reason, and I'm afraid my previous post wasn't very helpful. I didn't realize that at the time. I'll get back to you after I check a few things. Issue was created here: https://github.com/kobotoolbox/enketo-express/issues/403.

Martijn van de Rijdt

unread,
Feb 4, 2016, 1:54:00 PM2/4/16
to enketo-users, zaire...@gmail.com, sup...@enketo.org
Turns out there is no issue in Enketo (which reads XForms and support "\d" etc). Your issue is related to the KoBo Formbuilder. They will follow up with you (after the follow up they already provided when you posed the same question to them).

Cheers,
Martijn
Reply all
Reply to author
Forward
0 new messages