Brad Sawatzky Posted July 7, 2010 Share Posted July 7, 2010 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 More sharing options...
LesSjo Posted July 7, 2010 Share Posted July 7, 2010 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 More sharing options...
Brad Sawatzky Posted July 8, 2010 Author Share Posted July 8, 2010 Hey Les, Works like a charm, thanks. Beers are on me. Link to comment Share on other sites More sharing options...
LesSjo Posted July 8, 2010 Share Posted July 8, 2010 If I ever get to Calgary, I'll let you know. Link to comment Share on other sites More sharing options...
Brad Sawatzky Posted July 8, 2010 Author Share Posted July 8, 2010 If I make it to Fargo before you make it to Calgary, I'll bring a case. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.