Constraint for capturing specific entry in text

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

http://opendatakit.org/help/form-design/binding/
Regular Expression: Answer must be an email address like 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 >

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

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

You can read more about using regular expression constraints at https://docs.opendatakit.org/form-regex/. In particular, the page at 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/ should perhaps redirect to https://docs.opendatakit.org/form-logic? It would also be helpful to have some examples that used to be on that page shown inline.

1 Like

As others have indicated, what you are looking for is to use a regular expression; 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 :slight_smile: )

Check out email regex 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...

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

Valid email addresses that fail the regex above:

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