954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Textbox allows letters and numbers only

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.

Expotential
Newbie Poster
6 posts since Mar 2008
Reputation Points: 10
Solved Threads: 1
 

try to using ascii then trap when key press.

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

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
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

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.

Expotential
Newbie Poster
6 posts since Mar 2008
Reputation Points: 10
Solved Threads: 1
 

you're welcome friend :)

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

for more... details Contact
go4Expert.com

Nabeel19
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

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
Newbie Poster
1 post since Mar 2012
Reputation Points: 10
Solved Threads: 0
 
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..

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

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
kaozci
Newbie Poster
3 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You