# Constraint for capturing specific entry in text

**URL:** <https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407>\
**Category:** Support\
**Created:** [July 14, 2014, 3:05pm UTC](https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407 "2014-07-14T15:05:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Burland](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/p/58956e/32.png) [@Paul\_Burland](https://forum.getodk.org/u/Paul_Burland)\
**Post date:** [July 14, 2014, 3:05pm UTC](https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407/1 "2014-07-14T15:05:37Z")

</div>

Hi All,

I am trying to create a from whereby inspectors are initially required to  
enter a valid email address. As such I am trying to use a constraint to  
check that the entry contains the @ character, but not sure how or if this  
is the best way to do this.

Any assistance would be appreciated.

Many thanks,  
Paul

---

<div class="post-metadata">

**Author:** ![Koassi\_AKAKPO](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/k/e19b73/32.png) [@Koassi\_AKAKPO](https://forum.getodk.org/u/Koassi_AKAKPO)\
**Post date:** [July 14, 2014, 6:37pm UTC](https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407/2 "2014-07-14T18:37:14Z")

</div>

[http://opendatakit.org/help/form-design/binding/](http://opendatakit.org/help/form-design/binding/)  
Regular Expression: Answer must be an email address like [bob@aol.com](mailto:bob@aol.com)

> **···**
>
> Le lundi 14 juillet 2014 15:05:37 UTC, Paul Burland a écrit : \> \> Hi All, \> \> I am trying to create a from whereby inspectors are initially required to \> enter a valid email address. As such I am trying to use a constraint to \> check that the entry contains the @ character, but not sure how or if this \> is the best way to do this. \> \> Any assistance would be appreciated. \> \> Many thanks, \> Paul \>

---

<div class="post-metadata">

**Author:** ![Paul\_Burland](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/p/58956e/32.png) [@Paul\_Burland](https://forum.getodk.org/u/Paul_Burland)\
**Post date:** [July 15, 2014, 7:40am UTC](https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407/3 "2014-07-15T07:40:39Z")

</div>

Many thanks, cannot believe I missed that!!

Regards,  
Paul

> **···**
>
> On Monday, 14 July 2014 19:37:15 UTC+1, Mokpokpo ADJEODA wrote: \> \> http://opendatakit.org/help/form-design/binding/ \> Regular Expression: Answer must be an email address like b...@aol.com \> \> \> constraint="regex(., '[A-Za-z0-9.\_%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}')" \> jr:constraintMsg="this isn't a valid email address"/\> \> \> Le lundi 14 juillet 2014 15:05:37 UTC, Paul Burland a écrit : \>\> \>\> Hi All, \>\> \>\> I am trying to create a from whereby inspectors are initially required to \>\> enter a valid email address. As such I am trying to use a constraint to \>\> check that the entry contains the @ character, but not sure how or if this \>\> is the best way to do this. \>\> \>\> Any assistance would be appreciated. \>\> \>\> Many thanks, \>\> Paul \>\> \>

---

<div class="post-metadata">

**Author:** ![MKamal](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@MKamal](https://forum.getodk.org/u/MKamal)\
**Post date:** [June 4, 2018, 12:57pm UTC](https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407/4 "2018-06-04T12:57:41Z")

</div>

could u help me with the solution as the URL that u r posted is not working. Many thanks.

---

<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:** [June 4, 2018, 9:24pm UTC](https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407/5 "2018-06-04T21:24:17Z")

</div>

You can read more about using regular expression constraints at [https://docs.opendatakit.org/form-regex/](https://docs.opendatakit.org/form-regex/). In particular, the page at [https://gist.github.com/nerdsrescueme/1237767](https://gist.github.com/nerdsrescueme/1237767) has several examples you will be interested in.

The website was recently updated and some redirects may not be as helpful as they can be. @adammichaelwood I'm wondering whether [http://opendatakit.org/help/form-design/binding/](http://opendatakit.org/help/form-design/binding/) should perhaps redirect to [https://docs.opendatakit.org/form-logic](https://docs.opendatakit.org/form-logic)? It would also be helpful to have some examples that used to be on that page shown inline.

---

<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:** [June 4, 2018, 9:31pm UTC](https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407/6 "2018-06-04T21:31:10Z")

</div>

As others have indicated, what you are looking for is to use a [regular expression](https://docs.opendatakit.org/form-regex/); ie `constraint='regex(...)'`

Of course, the real issue is what is the proper regex for checking an email address? Well... that all rather depends on how precise you wanna get! If you want to be **really** pedantic about it, there's this:

`(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'\*+/=?^\_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])`

(and no, I didnt come up with that myself 🙂 )

Check out [email regex](http://emailregex.com/) if you want all the gory details. Basically, you will have to make a decision how precise you want your check to be - you can _really_ go nuts trying to come up with a regex that'll accept 100% valid emails and reject 100% invalid ones...

---

<div class="post-metadata">

**Author:** ![adammichaelwood](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/adammichaelwood/32/1698_2.png) [@adammichaelwood](https://forum.getodk.org/u/adammichaelwood)\
**Post date:** [June 12, 2018, 3:26pm UTC](https://forum.getodk.org/t/constraint-for-capturing-specific-entry-in-text/3407/7 "2018-06-12T15:26:38Z")

</div>

Depending on your context, you need to be aware of issues with expanded Unicode support in email.  
cf: [https://en.wikipedia.org/wiki/International\_email](https://en.wikipedia.org/wiki/International_email)

[Valid](https://tools.ietf.org/html/rfc6530) email addresses that fail the regex above:

用户@例子.广告  
अजय@डाटा.भारत  
квіточка@пошта.укр  
θσερ@εχαμπλε.ψομ  
Dörte@Sörensen.example.co  
аджай@экзампл.рус  
وأشوكا @ الهند
