Jump to content

Format Phone - Anyone? Arithmetic operation resulted in an overflow.

- - - - -

  • Please log in to reply
2 replies to this topic

#1
vertigo262

vertigo262

    Newbie

  • Members
  • Pip
  • 4 posts
Anyone know why this does this?

Server Error in '/' Application.
Arithmetic operation resulted in an overflow.

# <asp:Label ID="Label4" runat="server" Font-Size="Medium" Text='<%# GetPhoneFormat(Eval("Phone")) %>' />
#
#
# Function GetPhoneFormat(ByVal Phone As String) As String
#
# Dim PhoneFormat As String
# If IsDBNull(Phone) Or IsNothing(Phone) Then
# PhoneFormat = " "
# Else
#
# Phone = CInt(Phone).ToString("(000) 000-0000")
# PhoneFormat = "<b>Phone:</b> " & Phone
#
# End If
#
#
# Return PhoneFormat
# End Function
#

#2
vertigo262

vertigo262

    Newbie

  • Members
  • Pip
  • 4 posts
Someone gave me some better code. works

Dim cleanNumber As String = Regex.Replace(Phone, "[^0-9]", "")
Dim PhoneFormat As String = "<b>Phone:</b> " & Regex.Replace(cleanNumber, "(\d{3})(\d{3})(\d{4})", "($1) $2-$3")

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200

Quote

Arithmetic operation resulted in an overflow.
A phone number such as 000-000-0000 will result in an integer larger than 2.7 billion, which is the maximum a 32 bit signed integer can display. Regex is much easier to check with this.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users