top of page
Writer's pictureScott Ellis

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:

  1. I can do it in InfoPath

  2. I can do it in SharePoint

  3. I can custom code a solutionWell 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.


image

Then open the Manage Rules on the Ribbon of InfoPath


image

Next select New > Validation


image

You should now see this


image

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.

Condition

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

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

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


image

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))


image

It should end up looking like this:


image

So the result looks like this:


image
0 comments

Comments


bottom of page