Hi everyone! How do I make a textBox control to validate a tel nr field? For instance When the user enters 0127748222, It should be displayed as (012) 774-8222 in the textbox.
I need this to be done this way since this is the way i'll be storing the fields in the database.

Thanks

I won't guarantee that this code is bullet-proof, but give it a try:

Dim TempStr As String
Dim i As Integer
Const DIGITS As String = "0123456789"

TempStr = TextBox1.Text
' Strip to only digits. There may be a better way to remove non-digits off
Do Until String.IsNullOrEmpty(TempStr)
  For i = 0 To TempStr.Length - 1
    If DIGITS.IndexOf(TempStr(i)) < 0 Then
      ' Not digit, remove it
      TempStr = TempStr.Replace(TempStr(i), "")
      Continue Do
    End If
  Next i
  Exit Do
Loop
' Use custom format string
If Not String.IsNullOrEmpty(TempStr) Then
  TextBox1.Text = CLng(TempStr).ToString("'('0##')' ###'-'####")
End If

Thanx y'all, I Will do try your solutions, they seem to be right. And oh me, little did I realise that there was a masked textbox. Eish!!

This question has already been answered. Start a new discussion instead.