ASP VB.NET Format Phone Number For Masked Input

In order to be able to display phone numbers in text fields masked by Josh Bush’s jQuery Masked Input Plugin you need to provide e healthy string after reading the value from the database. This code snippet seemed to work for us quite well:

Dim regPhone As New Regex(“[^0-9]“)

If Trim(Phone).Length > 0 Then
txtPhone.Text = String.Format(“{0:(###) ###-####}”, CType(regPhone.Replace(Trim(Phone), [String].Empty), Int64))
or just simply:
txtPhone.Text =regPhone.Replace(Trim(Phone), [String].Empty))
End If

Tags: ,

Leave a Reply