# Field not validating with regex with correct data

**URL:** <https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573>\
**Category:** Support\
**Tags:** odk-central, enketo\
**Created:** [August 2, 2021, 5:52pm UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573 "2021-08-02T17:52:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardo1](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ricardo1/32/16032_2.png) [@Ricardo1](https://forum.getodk.org/u/Ricardo1)\
**Post date:** [August 2, 2021, 5:52pm UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/1 "2021-08-02T17:52:12Z")

</div>

```auto
<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.

 ![Screenshot from 2021-08-02 23-19-36](https://getodk.b-cdn.net/uploads/default/original/3X/f/a/fa27c80c4e4050fa4c8ab3c6455110321c922593.png)

---

<div class="post-metadata">

**Author:** ![danbjoseph](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/danbjoseph/32/21901_2.png) [@danbjoseph](https://forum.getodk.org/u/danbjoseph)\
**Post date:** [August 3, 2021, 1:28am UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/2 "2021-08-03T01:28:40Z")

</div>

Welcome to the ODK forum, @Ricardo1 ! We're glad you're here. When you get a chance, please [introduce yourself on this forum thread](https://forum.getodk.org/t/-/6671). Thanks for adding a profile image; it helps build community!

That expression works for me when tested in an XLSForm.  
[regex\_test.xlsx](https://forum.getodk.org/uploads/short-url/fvggqNx39qOV4jU4mJKblSjRGtY.xlsx) (8.7 KB)

```plaintext
+------+------+-------------+--------------------------+------------+
| 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](https://getodk.b-cdn.net/uploads/default/original/3X/f/c/fc36271f8985f858c7a148a0aa6d2d7c80f0c066.png)

![Screen Shot 2021-08-02 at 7.24.01 PM](https://getodk.b-cdn.net/uploads/default/original/3X/f/8/f8fa57d0412eaf8140fab449630725467f7697d6.png)

![Screen Shot 2021-08-02 at 7.24.29 PM](https://getodk.b-cdn.net/uploads/default/original/3X/e/e/ee38786979cf4f4c6b8b69aae295836f385b9490.png)

---

<div class="post-metadata">

**Author:** ![Ricardo1](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ricardo1/32/16032_2.png) [@Ricardo1](https://forum.getodk.org/u/Ricardo1)\
**Post date:** [August 3, 2021, 8:07am UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/3 "2021-08-03T08:07:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Xiphware](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/xiphware/32/2587_2.png) [@Xiphware](https://forum.getodk.org/u/Xiphware)\
**Post date:** [August 3, 2021, 8:50am UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/4 "2021-08-03T08:50:49Z")

</div>

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...]

---

<div class="post-metadata">

**Author:** ![Ricardo1](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ricardo1/32/16032_2.png) [@Ricardo1](https://forum.getodk.org/u/Ricardo1)\
**Post date:** [August 3, 2021, 9:07am UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/5 "2021-08-03T09:07:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matthew\_White](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/matthew_white/32/1654_2.png) [@Matthew\_White](https://forum.getodk.org/u/Matthew_White)\
**Post date:** [August 3, 2021, 2:11pm UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/6 "2021-08-03T14:11:13Z")

</div>

> [@Ricardo1](#):
>
> it is upper case 'R' in documentation.

I've filed a docs issue so that we can keep track of that: [https://github.com/getodk/docs/issues/1378](https://github.com/getodk/docs/issues/1378)

> [@Ricardo1](#):
>
> I am using v1.2.2 in which it seems that .xls definition upload is not suppoorted and only .xml format.

Are you using Central v1.2.2? If so, XLSForm upload should be supported: [https://docs.getodk.org/central-forms/#uploading-a-form-to-odk-central](https://docs.getodk.org/central-forms/#uploading-a-form-to-odk-central). Feel free to create a separate forum topic if you run into issues there!

---

<div class="post-metadata">

**Author:** ![Ricardo1](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ricardo1/32/16032_2.png) [@Ricardo1](https://forum.getodk.org/u/Ricardo1)\
**Post date:** [August 3, 2021, 3:29pm UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/7 "2021-08-03T15:29:33Z")

</div>

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:

 ![Screenshot from 2021-08-03 20-50-45](https://getodk.b-cdn.net/uploads/default/original/3X/f/0/f0c4a51b3ad891690c2c52242e2546ecb6ed5e78.png)

---

<div class="post-metadata">

**Author:** ![danbjoseph](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/danbjoseph/32/21901_2.png) [@danbjoseph](https://forum.getodk.org/u/danbjoseph)\
**Post date:** [August 3, 2021, 4:41pm UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/8 "2021-08-03T16:41:13Z")

</div>

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](https://getodk.b-cdn.net/uploads/default/original/3X/7/2/7229d8208de741cd6e551f1dbe5d327b80b82afa.png)

![Screen Shot 2021-08-03 at 10.38.10 AM](https://getodk.b-cdn.net/uploads/default/original/3X/0/e/0ee48bea814e457f142a2c0ff507d5fc82ab3d16.png)

---

<div class="post-metadata">

**Author:** ![Xiphware](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/xiphware/32/2587_2.png) [@Xiphware](https://forum.getodk.org/u/Xiphware)\
**Post date:** [August 3, 2021, 10:01pm UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/9 "2021-08-03T22:01:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ricardo1](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ricardo1/32/16032_2.png) [@Ricardo1](https://forum.getodk.org/u/Ricardo1)\
**Post date:** [August 4, 2021, 1:06pm UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/10 "2021-08-04T13:06:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [August 5, 2021, 4:45am UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/11 "2021-08-05T04:45:27Z")

</div>

> [@Xiphware](#):
>
> Validate appears to pickup up the typo when `Regex(...)` is misspelled in a _calculation_ Xpath expression, but not in a _constraint_ expression.

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.

---

<div class="post-metadata">

**Author:** ![Xiphware](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/xiphware/32/2587_2.png) [@Xiphware](https://forum.getodk.org/u/Xiphware)\
**Post date:** [August 5, 2021, 7:47am UTC](https://forum.getodk.org/t/field-not-validating-with-regex-with-correct-data/34573/12 "2021-08-05T07:47:21Z")

</div>

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...
