Welcome to WebmasterWorld Guest from 35.153.73.72

Forum Moderators: ocean10000

Message Too Old, No Replies

Displaying phone numbers with alphabetic characters

     
9:12 pm on Jul 30, 2008 (gmt 0)

New User

10+ Year Member

joined:July 16, 2006
posts:8
votes: 0


Hi there,

I'm trying to work out a way to display alphabetic characters that occassionally appear in phone numbers (for instance, 866-555-BIKE). They way I have it setup now they are simply ignored. Here's what I currently have:

<%# String.Format("{0:###-###-####}", Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "ItemValue").ToString().Replace("-","")))%>

I'm not trying to convert the alpha characters to numbers or anything, just display them.

I'd appreciate any pointers.

4:21 am on July 31, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


Have you tried removing:
Convert.ToDecimal()
5:05 pm on July 31, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


I've looked into it further, and I don't think it is possible to format it with # (which is a digit placeholder)

You could use the following:


<%
string myString = (DataBinder.Eval(Container.DataItem, "ItemValue").ToString().Replace("-",""));
response.write(myString.Substring(0, 3) + "-" + myString.Substring(3, 3) + "-" + myString.Substring(6, 4));
%>