Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing code...need help

Status
Not open for further replies.

NeoCryptic

Programmer
Joined
Jul 13, 2006
Messages
2
Location
US
i have this code that formatted a phone number to (123) 456-7899. i would like to change it so that it can have bullets instead 123?456?7899. the code is below. someone said the symbol for bullets is &#183...but i'm not sure the syntax to add that in.

thanks.


var formatStyle01 = "($1) $2-$3";

var formatStyle02 = "$1-$2-";

var theNumber = Field("TopPhone1");



return formatNumber(theNumber);

function formatNumber(number01){

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

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

var pattern03=/^[^\d]+(\d{3})[^\d]+\s+(\d{3})[^\d]+(\d{4})$/;

var pattern04=/^(\d{3})(\d{3})(\d{4})$/;

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

var pattern06=/^(\d{3})(\d{4})$/;

if (number01.length == 7){

number01 = number01.replace(patter06, formatStyle02);

return number01;

}else if (number01.length == 8){

number01 = number01.replace(pattern05, formatStyle02);

return number01;

}else if (number01.length == 10){

number01 = number01.replace(pattern04, formatStyle01);

return number01;

}else if (number01.length == 12){

number01 = number01.replace(pattern04, formatStyle01);

return number01;

}else if (number01.length == 13){

number01 = number01.replace(pattern02, formatStyle01);

return number01;

}else if (number01.length == 14){

number01 = number01.replace(pattern03, formatStyle01);

return number01;

}else

return theNumber;

}
 
Well that is interesting code. I think if you simply change the dashes to · it will work. Because the regular expresssions are merely building strings. When a browser sees a dash, it displays a dash; when it sees a metacharacter ( I think that is what · is called) the browser displays the character it represents. The issue with metacharacters is more a matter of what can be typed from a keyboard than anthing else.

Give it a try. Let me know.
 
yeah, already tried that...didn't work. tried putting in &#183, &183, \&#183, moving the quotes and putting +, but it didn't like any. i know i gotta just change this line...but nothing has worked?

thanks for the reply :)

var formatStyle01 = "($1) $2-$3";
 
Using · should work in certain context, but not in some others. As you said it doesn't, to work in that context, you could do this.
[tt]
formatStyle01 = "$1" + String.fromCharCode(183) + "$2" + String.fromCharCode(183) + "$3";
return formatNumber(theNumber);
[/tt]
 
well the metacharacters begin with an ampersand and end with a semi-colon. i dont see the semi-colon in your posts. maybe that is the problem.

Code:
<html><body>

abcdefg&#183;&#183;&#183;&#183;

<script>
var formatStyle02 = "$1&#183;$2";
var pattern06=/^(\d{3}).(\d{4})$/;
var number01 = "555.1212";
number01 = number01.replace(pattern06, formatStyle02);
document.write(number01);
</script>
</body></html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top