I am working on a program that requires registration of a username however I do not want users to be able to register usernames with any symbols or spaces only letters and numbers.

I honestly dont know where to start on this.

Thanks.

try this following code, this code didn't allowed you to input any special character just numbers and letters:

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 65 To 90, 48 To 57, 8 ' A-Z, 0-9 and backspace
        'Let these key codes pass through
        Case 97 To 122, 8 'a-z and backspace
        'Let these key codes pass through
        Case Else
        'All others get trapped
        KeyAscii = 0 ' set ascii 0 to trap others input
    End Select
End Sub
Comments
:D SIIIIIIIIPpppp
great
simple but excellent

try this following code, this code didn't allowed you to input any special character just numbers and letters:

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 65 To 90, 48 To 57, 8 ' A-Z, 0-9 and backspace
        'Let these key codes pass through
        Case 97 To 122, 8 'a-z and backspace
        'Let these key codes pass through
        Case Else
        'All others get trapped
        KeyAscii = 0 ' set ascii 0 to trap others input
    End Select
End Sub

thanks that worked great.

please help i want my textbox phoneno to allow only numbers and only 10 numbers to b allowed please guide me using VB.NET 2008

please help i want my textbox phoneno to allow only numbers and only 10 numbers to b allowed please guide me using VB.NET 2008

harshi sarvaiya..make your own thread here.
There are many members will help you more..

only write what you want

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Trim(Text1.Text)) = 10 Then Text3.SetFocus
Dim N$
N = "0123456789"
If KeyAscii <> 8 Then
If InStr(N, Chr(KeyAscii)) = 0 Then
Beep
KeyAscii = 0
Exit Sub
End If
End If
End Sub

Edited 4 Years Ago by WaltP: n/a

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