Monday, October 27, 2008

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

Post a Comment