Okay, I figured it out, and here it is for everyone else's benefit. This is
all designed to yield output like:

Cell: (123) 456-7890

This comprises two fields, <<Phone2Lbl>> and <<Phone2>>

Note, with this particular job, this phone field is a 2nd option, it can be
left empty. It works in conjunction with another field (<<Phone2Lbl>>) that
I have configured as a drop-down selection for a "phone label". The user can
choose from options such as "Cell:", "Pgr:", etc. to serve as a label for
this phone number. I use two rules to work with these two fields.

The first rule (<<rule_FormatPhone2>>) formats the phone number (to be
consistent with my other phone numbers).

The second rule (<<rule_HidePhone2>>) handles the display of the two fields
or the suppressing of the line if either the phone, or phone label field is
empty.

Here they are:

/*
 * rule_HidePhone2
 */

if (Field("Phone2Lbl") == "" || Field("Phone2") == "")
        return "";
else
        return Field("Phone2Lbl") + " " + Rule("rule_FormatPhone2");
// end rule_HidePhone2

/*
 * rule_FormatPhone2
 */

Var1="Phone2"; // What is our phone field?
CaseSelection="Format 3"; // Which format (below) do we want to use

// Format 1 = 123.456.7890
if(CaseSelection == "Format 1")
{
var formatStyle01 = "$1.$2";                            //simple 7 digit
phone
var formatStyle02 = "$1.$2.$3";                         //simple 10 digit
phone
var formatStyle03 = "+$1 $2.$3.$4";                     //10 digit phone
starts with 1
var formatStyle04 = "$1.$2.$3 ext.$4";          //10 digit phone with
extension
var formatStyle05 = "+$1 $2.$3.$4 ext.$5";      //10 digit phone starts with
1 with extension
var formatStyle06 = "$1.$2 ext.$3";                     //7 digit phone with
extension

var thisNumber = Field(Var1);

return formatNumber(Trim(thisNumber));
}

// Format 2 = 123-456-7890
if(CaseSelection == "Format 2")
{
var formatStyle01 = "$1-$2";                            //simple 7 digit
phone
var formatStyle02 = "$1-$2-$3";                         //simple 10 digit
phone
var formatStyle03 = "+$1 $2-$3-$4";                     //10 digit phone
starts with 1
var formatStyle04 = "$1-$2-$3 ext.$4";          //10 digit phone with
extension
var formatStyle05 = "+$1 $2-$3-$4 ext.$5";      //10 digit phone starts with
1 with extension
var formatStyle06 = "$1-$2 ext.$3";                     //7 digit phone with
extension

var thisNumber = Field(Var1);

return formatNumber(Trim(thisNumber));
}

// Format 3 = (123) 456-7890
if(CaseSelection == "Format 3")
{
var formatStyle01 = "$1-$2";                            //simple 7 digit
phone
var formatStyle02 = "($1) $2-$3";                       //simple 10 digit
phone
var formatStyle03 = "($2) $3-$4";                       //10 digit phone
starts with 1
var formatStyle04 = "($1) $2-$3 ext.$4";        //10 digit phone with
extension
var formatStyle05 = "($2) $3-$4 ext.$5";        //10 digit phone starts with
1 with extension
var formatStyle06 = "$1-$2 ext.$3";                     //7 digit phone with
extension

// The two formats below are the original formatStyles. They were altered
(above)
// to strip off the country code from the phone number, as we are in the US,
we don't
// need this.
//
// var formatStyle03 = "+$1 ($2) $3-$4";                //10 digit phone
starts with 1
// var formatStyle05 = "+$1 ($2) $3-$4 ext.$5"; //10 digit phone starts with
1 with extension

var thisNumber = Field(Var1);

return formatNumber(Trim(thisNumber));
}

// Format 4 = (123)456.7890
if(CaseSelection == "Format 4")
{
var formatStyle01 = "$1.$2";                            //simple 7 digit
phone
var formatStyle02 = "($1)$2.$3";                        //simple 10 digit
phone
var formatStyle03 = "+$1 ($2)$3.$4";            //10 digit phone starts with
1
var formatStyle04 = "($1)$2.$3 ext.$4";         //10 digit phone with
extension
var formatStyle05 = "+$1 ($2)$3.$4 ext.$5";     //10 digit phone starts with
1 with extension
var formatStyle06 = "$1.$2 ext.$3";                     //7 digit phone with
extension

var thisNumber = Field(Var1);

return formatNumber(Trim(thisNumber));
}

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

return formatNumber(Trim(thisNumber));

function formatNumber(number01){

var pattern01 = /^(\d{3})[^\d]*(\d{4})$/;

//   //2201727 or 220-1727 or 220- 1727
        var pattern02 = /^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/;

// 8002201727 or 800-220-1727 or (800)220-1727 or (800) 220-1727
        var pattern03 = /^\+?(\d{1})[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/;

// 18002201727 or 1-800-220-1727 or +1 (800) 220-1727
        var pattern04 =
/^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;
// 800-220-1727 ext 12345 or (800) 220-1727 ext 12345
        var pattern05 =
/^\+?(\d{1})[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;
// 1-800-220-1727 ext 12345 or +1 (800) 220-1727 ext 12345
        var pattern06 = /^(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;

// 2201727 ext 1234 or 220-1727 ext 1234 or 220- 1727 ext 1234
        var patternEndExt = /(.)[x#n](.)/;
        var patternStart1 = /^[\D]*[1]/;

        if(number01.match(pattern01)){
                number01 = number01.replace(pattern01, formatStyle01);
                return number01;
        } else if(number01.match(pattern02)){
                number01 = number01.replace(pattern02, formatStyle02);
                return number01;
        } else if(number01.match(pattern03)){
                if (number01.match(patternStart1)){
                        number01 = number01.replace(pattern03,
formatStyle03);
                        return number01;
                } else {
                        return number01;
                }
        } else if(number01.match(pattern04)){
                        number01 = number01.replace(pattern04,
formatStyle04);
                        return number01;
        } else if(number01.match(pattern05)){
                        number01 = number01.replace(pattern05,
formatStyle05);
                        return number01;
        }  else if(number01.match(pattern06)){
                        number01 = number01.replace(pattern06,
formatStyle06);
                        return number01;
        } else {
                //return "no match any pattern";
                return number01;
        }
} // end rule_FormatPhone2


-----Original Message-----
From: Craig Daters [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 12, 2007 11:30 AM
To: FusionPro Users Forum
Subject: [fusionpro] Change phone format rule

I need the "Change phone format rule" to give me this format option "(123)
456-7890"

Note the space between the area code and number. I convert the XML rule to
javascript, but I am not a regex kind of guy, so therefore I do not know
where to add the space. Can any one out there help me out with this one?

Craig D.

Craig Daters | Systems Administrator | [EMAIL PROTECTED]

West Press
1663 West Grant Road
Tucson, Arizona 85745-1433
(520) 624-4939 x208
(520) 624-2715 fax
www.westpress.com



--
Please note: It is the policy of West Press that all e-mail
sent to and from any @westpress.com address may be recorded
and monitored. Unless it is West Press related business,
please do not send any material of a private, personal,
or confidential nature to this or any @westpress.com
e-mail address.

This message has been scanned for UCE (spam), viruses,
and dangerous content, and is believed to be clean 


--
Users of FusionPro Desktop have unlimited free email support. Contact Printable 
Support at [EMAIL PROTECTED] 
--
View FusionPro Knowledge Base, FusionPro Samples at
www.printable.com/vdp/desktop.htm

--
You are currently subscribed to fusionpro as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
--


--
Note:  All e-mail sent to or from this address will be received or otherwise 
recorded by the e-mail recipients of this forum. It is subject to archival, 
monitoring or review by, and/or disclosure to someone other than the recipient. 
Our privacy policy is posted on www.printplanet.com
--

Reply via email to