Jump to content

11 Digit Phone Format Rule


Brad Sawatzky

Recommended Posts

I'm working on a business card template that requires an 11 digit phone number to be formatted in a specific way. I initialy though it wouldn't be a problem, I'd just use a change phone format rule and be done with it. Only trouble is there isn't one to accomodate an 11 digit number.

I need the number "+61 7 311 22697" formatted to look like

"+61 (7) 311 22697" and far be it for me to start monkeying around below the line that reads "Do Not Edit Below This Line."

If anyone can lend a hand, I'll buy them a beer.

Thanks

Link to comment
Share on other sites

Try this. Copy the inserted code into a new rule. Just call the rule in the place of the phone in your text box.

 

Var1="Phone";//change this to whatever your field name is...

var formatStyle = "+$1 $2 $3 $4";            //simple 11 digit phone +61 7 311 22697
var thisNumber = Field(Var1);
return formatNumber(Trim(thisNumber));

//////////////////////////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE ///////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

return formatNumber(Trim(thisNumber));

function formatNumber(number01){

   var pattern = /^[\D]*(\d{2})[\D]*(\d{1})[\D]*(\d{3})[\D]*(\d{5})$/;                   
// 61731122697 (11 digit number)

   if(number01.match(pattern)){
       number01 = number01.replace(pattern, formatStyle);
       return number01;
   } else {
       return '<color rgb="ff0000">' + "* incorrect format" + '</color>';
   }    
}

Make sure you have the "Treat returned strings as tagged text" box checked.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...