Jump to content

Altering the Format Phone Number Rule


KayEll

Recommended Posts

I was hoping someone here could help me with what is I'm sure a very simple alteration to the "Change phone number format" rule.

 

I need the number to have a space after the closing parens of the area code. I want it to look like this: (###) ###-####

That's not available in the options in the pull down menu, there is no space between area code and prefix, and I cannot figure out where to add the space in the javascript. Can someone show me where to add it in the script below, if possible?

 

I emailed this to Alex at Printable and he answered with a solution that required setting up tab stops for all three parts of the number, however I was having a real problem getting them to line up so I am hoping it's possible to just add the space somewhere in the script. If anyone knows where exactly to do that, I would appreciate the help. This script is much more complicated than the ones I am used to writing.

 

Thanks for any suggestions,

KayEll

 

 

 

 

 

var Var1 = "Direct";

var CaseSelection = "Format 3";

 

 

 

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

}

 

 

 

 

 

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

}

 

 

 

 

 

if(CaseSelection == "Format 3")

{

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

}

 

 

 

 

 

 

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;

}

}

Link to comment
Share on other sites

I was hoping someone here could help me with what is I'm sure a very simple alteration to the "Change phone number format" rule.

 

I need the number to have a space after the closing parens of the area code. I want it to look like this: (###) ###-####

Since you appear to have chosen "Format 3" for the static value of CaseSelection:

var Var1 = "Direct";
var CaseSelection = "Format 3";

you need to find this code in the current rule:

if(CaseSelection == "Format 3")
{
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));
}

and make the changes in red:

if(CaseSelection == "Format 3")
{
var formatStyle01 = "$1-$2"; //simple 7 digit phone
var formatStyle02 = [color=red]"($1) $2-$3"[/color];	 //simple 10 digit phone
var formatStyle03 = [color=red]"+$1 ($2) $3-$4"[/color];	 //10 digit phone starts with 1
var formatStyle04 = [color=red]"($1) $2-$3 ext.$4"[/color];	 //10 digit phone with extension
var formatStyle05 = [color=red]"+$1 ($2) $3-$4 ext.$5"[/color];	//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));
}

Technically, you could make the same changes to all format values in all CaseSelection possibilities, but as long as you do not have plans to alter the value of CaseSelection above, this minimal change should do the trick.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...