InfoPath is a great tool when you need to collect data from the users, especially in SharePoint.  I especially like the browser enabled enhancements over the old 2007 and it’s a great way to spruce up the standard NewForm.aspx and EditForm.aspx pages when you want to put some logic and validation for what the user is inputting, for example phone numbers.

From a basic standpoint, a phone number has to be entered in the format (123)555-7899. There is a way to make this happen – even in browser forms – using something called Regular Expressions (Which by they way if you don’t know about this stuff you should go check out the tutorials here at . You won’t see the phrase "regular expression" in InfoPath but you will see something like "matches pattern" or "does not match pattern" – which are regular expressions. Here’s the basic way they work:

Using either Conditional Formatting or Data Validation in your InfoPath form, you should have [Field1] [Does not match pattern] [RegEx Pattern] – and the action or tooltip should either disable/hide the control or have a message stating something like "Please type your information in the correct format". Patterns use the following building blocks:

  1. If you want to have a symbol for any letter: \p{L}
  2. If you want to have a symbol for any character (letter, number, or symbol): . (yes, that’s a period)
  3. If you want to have a symbol for any digit: \d
  4. If you want to use a period, parenthesis, or dash symbol: \. or \( or \-
  5. If you want one of the above to be used a certain number of times, you can use an *, a +, or a ? but they must go AFTER the thing you want to be only used a certain number of times. * = 0 or more of that thing (e.g. \d* means either no digit up to a huge number – as big as you want). + = at least 1 or more of that thing (e.g. \d+ means at least 1 digit but can get to be as big as you want). ? = 0 or 1 of that thing (e.g. \d? means either a single digit or nothing).

So, how does this help you with making people enter phone numbers or emails correctly? Here’s what the patterns should look like for phone numbers: \d?\(\d\d\d\)\d\d\d\-\d\d\d\d

Notice how there’s that optional digit at the beginning for the USA country code? Obviously, international numbers will be a bit more complicated, but this will make people type in their phone numbers as 1(123)456-7899 or (123)456-7899 – depending on if they want a country code.  Easy data validation with RegEx!