Custom Rule for Telephone Field in InfoPath 2010 Form

So I am working on a project and they want to have some customer facing forms. One of the challenges is they want to have some validation/event handling that will ensure the phone format is “Just So”. The main reason is that the field in the SharePoint site needs to be visible to Call Technicians. They also want this information to flow into a CRM system.

What I wanted to do was achieve the perfect (919) 555-1212 format without custom code. So I have three options:

  • I can do it in InfoPath
  • I can do it in SharePoint
  • I can custom code a solution
    Well here is the easiest solution…better it is OOB so no pain, and easy to maintain.

First create a Text(string) Phone Number field, nothing special. I am a fan of making this A required field “since we are doing so much work”. See the Field Properties below for the example.


Then open the Manage Rules on the Ribbon of InfoPath


Next select New > Validation


You should now see this


Now give it a name (Details for:) I like to call it something like Phone Number Validation

Now we need to setup some Conditions, this is ensure the length of the all the numbers come in as a 0123456789 format, so we can properly apply our formatting rule later.


Telephone Number : does not match pattern : Phone number : and

The expression : string-length(translate(., “()- “, “”)) = 10 : and

The expression : string-length(translate(., “()- 0123456789”, “”)) = 0 : and


Rule Details

Now we need to set the format translation, big fan of the ConCat command. You can see it in action.

Action: Set a field’s value

Field: .

Value: concat(“(“, substring(translate(., “()- “, “”), 1, 3), “) “, substring(translate(., “()- “, “”), 4, 3), “-“, substring(translate(., “()- “, “”), 7, 4))


It should end up looking like this:


So the result looks like this:



10 Replies to “Custom Rule for Telephone Field in InfoPath 2010 Form”

  1. Click on the FX button and paste the command in, replace the quotes and then click Verify formula, this will tell you what is wrong, for example even though I copied and pasted at the end I was missing a left parenthesis and a comma.

  2. This is one is for the Zipcode + 4 (relatively the same if you compare it)

    Zipcode + 4 for a text box on infopath form
    If you want to create a Zipcode + 4 format on a infopath form :

    1. Add a text field to the form (Even if it is the list or a blank form)
    2. Select the text box and click on Manage Rules

    4. Add a rule to your textbox control with the following conditions (make sure to select “and” operator):
    a. field “does not match pattern” Zipcode + 4
    b. the expression: string-length(translate(., “()- “, “”)) = 9
    c. the expression: string-length(translate(., “()- 0123456789”, “”)) = 0
    5. Add action to the rule:
    a. Set a field’s value
    b. Select your textbox field
    c. Insert formula for the value (click the fx button): concat( substring(translate(., “()- “, “”), 1, 2), substring(translate(., “()- “, “”), 3, 3), “-“, substring(translate(., “()- “, “”), 6, 4))

  3. In the Rules Details window, InfoPath won’t allow me to enter a period as the field. I had to choose the field. I applied the rest of the tutorial and had to type the quotation marks as straight quotes for InfoPath to accept the vaules. I’m not getting any errors but I’m not getting the phone format either. Any suggestions? Thanks in advance for your help, Jerri

    1. I too having the same issue by default it looks like “() -“. Having any solution to make text box empty after clearing the data.

  4. I also need the same help with my list. However I deal with numbers outside the US. What could the rules look like to include country codes?

    1. Easy to alter it to use periods as the separator…..

      Change the custom formatting rule to \d\d\d\.\d\d\d\.\d\d\d\d
      Then change the formatting fule to concat(substring(translate(., “.”, “”), 1, 3), “.”, substring(translate(., “.”, “”), 4, 3), “.”, substring(translate(., “.”, “”), 7, 4))


  5. Does it matter that the quotation marks in the code above are open or closed or straight quotes? I’m having trouble getting this to work. Thanks,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s