Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 format phone number

Author  Topic 

ntn104
Posting Yak Master

175 Posts

Posted - 2010-09-30 : 07:37:14
Hello,

How would I write a statement that can indicate if the phone number is blank or not show then display (xxx)xxx-xxxx. Below is my current code, but I got error message. Thanks,

<% if len(trim(rsGen("BUS_TEL_NUMBER")))>0
then ="(" & Left(rsGen("BUS_TEL_NUMBER"),3) & ") " & Mid(rsGen("BUS_TEL_NUMBER"),4,3) & "-" & Mid(rsGen("BUS_TEL_NUMBER"),7,4)
else "(XXX) XXX-XXXX"
End If
%>

lazycoder
Starting Member

12 Posts

Posted - 2010-10-01 : 05:27:31
[code] Dim sTelNumber As String
sTelNumber = "5486651122"
Dim sFormatedTelNumber As String
If (Not String.IsNullOrEmpty(sTelNumber)) Then
Dim nTelNumber As Long
nTelNumber = Long.Parse(sTelNumber)
sFormatedTelNumber = nTelNumber.ToString("(###) ### - ####")
Else
sFormatedTelNumber = "(XXX) XXX-XXXX"
End If[/code]

Put it to a function and call from the page

-----------------
http://it.expertmonster.com/
Go to Top of Page
   

- Advertisement -