this should work for you.
Dawn

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("phone1");

////////////////////////////////////////////////////////////////////////////
//////////////////////////
// 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*[Xx\-\.\*#Nn]\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*[Xx\-\.\*#Nn]\D*(\d+)$/;
// 1-800-220-1727 ext 12345 or +1 (800) 220-1727 ext 12345
    var pattern06 = /^(\d{3})[\D]*(\d{4})\D*[Xx\-\.\*#Nn]\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;
    }    
}


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