Bobski Bobski - 1 year ago 62 Question

VB.NET removing formatting from a formatted Phone number before inserting into SQL Server

I have a string when a telephone number is inputted - there is a mask so it always looks like (123) 456-7890 - I'd like to take the formatting out before saving it to the DB. I have it set up to only 10 charachters as nvarchar(10) - I only need it to be numbers like this 1234567890.

Answer Source

Another way to do it(basically replace every non number character with ""):

Dim phone as string = "(123) 456-7890 -"
Dim match as string = Regex.Replace(phone, "[^\d]", "")


This outputs to: 1234567890

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download