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 to using ascii then trap when key press.

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
commented: simple but excellent +1
commented: great +1
commented: :D SIIIIIIIIPpppp +1

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.

you're welcome friend :)

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.