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.

3 comments:

davidwilk said...

Dude - you rock - thanks for posting.

Unknown said...

Thank you so much for posting this simple but workable solution. It did the trick for me.

Stevizard

TA said...

Yeah, this really helps, but there are many alternative approaches. One of them I am using now is new, free and quite intelligent Form Builder Engine which is SharePoint based and it has the functionality to create and test different rules connected to your form fields. It is easily managed, developed and usable. For me it's precious and saving my time and efforts.