InfoPath Pattern matching – “Email” field
While teaching the InfoPath/Workflow class last week, I had the need to restrict a textbox control in an InfoPath form to only contain emails. If an invalid email is inserted, it should throw a validation error. Out of the box, the patterns provided by InfoPath are very limited. It only provides patterns for Phone Number, SSN, and Zip code:
I thought surely somewhere out on the web I would find the pattern needed for this, but to my surprise, I couldn’t find “a working one” (doesn’t mean that it doesn’t exist, but I just couldn’t find one after an extensive search). Here are the ones I did find and either they just didn’t work or were limiting in nature:
- http://bharatsukhwal2000.spaces.live.com/blog/cns!CDD1BF7F2239C3B!213.entry
- http://www.eggheadcafe.com/software/aspnet/29731834/email-fomatting-pattern.aspx
- http://www.infopathdev.com/forums/p/2868/6062.aspx
So I ended up creating a simple pattern myself:
.+@.+\..+
This might not catch All types of invalid emails, but it does catch quite a lot of them. Hope this post helps someone experiencing the same frustration as I did last week.
Recent Comments