Field not validating with regex with correct data

<bind nodeset="/data/group_ey66y74/EMIS_Number" type="string" required="true()" constraint="Regex(.,'^[0-9]{9,12}$')" jr:constraintMsg="EMIS can have minimum 9 and maximum 12 characters."/>

This is the regex i use for EMIS field.
But I type characters between 9 and 12(a.t. regex expression) it throws the constraint msg error.

Welcome to the ODK forum, @Ricardo1 ! We're glad you're here. When you get a chance, please introduce yourself on this forum thread. Thanks for adding a profile image; it helps build community!

That expression works for me when tested in an XLSForm.
regex_test.xlsx (8.7 KB)

| type | name |    label    |        constraint        | appearance |
| text | emis | EMIS Number | regex(.,'^[0-9]{9,12}$') | numbers    |

Screen Shot 2021-08-02 at 7.23.53 PM

Screen Shot 2021-08-02 at 7.24.01 PM

Screen Shot 2021-08-02 at 7.24.29 PM

1 Like

Hey @danbjoseph thanks for replying.
I am using v1.2.2 in which it seems that .xls definition upload is not suppoorted and only .xml format.
Which version are you using?

long shot... but there is no harm making sure you use 'regex', not 'Regex' [I cant remember off top of head if javaRosa is case-sensitive when it comes to XPath function names...]


@Xiphware thank you sir it worked.I did not expect lowering case would solve the issue.But it is upper case 'R' in documentation.

1 Like

I've filed a docs issue so that we can keep track of that:

Are you using Central v1.2.2? If so, XLSForm upload should be supported: Feel free to create a separate forum topic if you run into issues there!

hi @Matthew_White in regards to 2nd point yes im using odk central v1.2.2 and the upload is possible in both .xml ans .xls but download is available only in .xml format.
Attaching a ss for verification:

What type of file are you uploading? If you upload the XML XForm, you will only be able to download XML. However, Central accepts XLSForm and will then offer downloads in either format. I would recommend authoring your forms in XLSForm and letting the server deal with the conversion and provisioning the form to phones.

Screen Shot 2021-08-03 at 10.38.02 AM

Screen Shot 2021-08-03 at 10.38.10 AM


Interesting... Validate appears to pickup up the typo when Regex(...) is misspelled in a calculation Xpath expression, but not in a constraint expression.


Yeah the option is available now after uploading xls format.Thanks for the help.

Validate doesn’t do any static analysis on the form definition. It just evaluates the form as a form filling client would with the default instance values. So indeed, there are certain issues it cannot catch. A calculation on a relevant node would be evaluated and so issues there would generally be caught except for cases like an expression in an if case that is not evaluated. A constraint expression may or may not be evaluated depending on whether there field is required, etc.

1 Like

Thanks! I seemed to remember that Validate wasn't doing a thorough static analysis of XPath expressions, but I'd forgotten that it was instead just running everything with the default instance values, and seeing what fell out...

Basically, dont rely on Validate picking up errors in your calculate/constraint/relevant/readonly expressions. Although sometimes you might get lucky...

1 Like