I'm just trying to add a simple function to the textbox for security that if i only allow 0 - 9 Numbers and i try to put a letter it wont let me i forgot the code so if any can help me ...

Nvm got it XD

Nvm Again how do i set my own chars ??? like i put the chars that i want to be allowed

1234567890.-qwertyuiopasdfghjklzxcvbnm

Does chars i want to be allowed ...

i got so far this in KeyPress Event

If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
            e.Handled = True
        End If

But it only let me use

1 2 3 4 5 6 7 8 9 0 and .

i need to allow

q w e r t y u i o p a s d f g h j k l z x c v b n m and -

Well whatever Solved .... i used a manually & simple Code for anyone that want it ...

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." AndAlso e.KeyChar <> "-" AndAlso e.KeyChar <> "q" AndAlso e.KeyChar <> "w" AndAlso e.KeyChar <> "e" AndAlso e.KeyChar <> "r" AndAlso e.KeyChar <> "t" AndAlso e.KeyChar <> "y" AndAlso e.KeyChar <> "u" AndAlso e.KeyChar <> "i" AndAlso e.KeyChar <> "o" AndAlso e.KeyChar <> "p" AndAlso e.KeyChar <> "a" AndAlso e.KeyChar <> "s" AndAlso e.KeyChar <> "d" AndAlso e.KeyChar <> "f" AndAlso e.KeyChar <> "g" AndAlso e.KeyChar <> "h" AndAlso e.KeyChar <> "j" AndAlso e.KeyChar <> "k" AndAlso e.KeyChar <> "l" AndAlso e.KeyChar <> "z" AndAlso e.KeyChar <> "x" AndAlso e.KeyChar <> "c" AndAlso e.KeyChar <> "v" AndAlso e.KeyChar <> "b" AndAlso e.KeyChar <> "n" AndAlso e.KeyChar <> "m" AndAlso e.KeyChar <> "Q" AndAlso e.KeyChar <> "W" AndAlso e.KeyChar <> "E" AndAlso e.KeyChar <> "R" AndAlso e.KeyChar <> "T" AndAlso e.KeyChar <> "Y" AndAlso e.KeyChar <> "U" AndAlso e.KeyChar <> "I" AndAlso e.KeyChar <> "O" AndAlso e.KeyChar <> "P" AndAlso e.KeyChar <> "A" AndAlso e.KeyChar <> "S" AndAlso e.KeyChar <> "D" AndAlso e.KeyChar <> "F" AndAlso e.KeyChar <> "G" AndAlso e.KeyChar <> "H" AndAlso e.KeyChar <> "J" AndAlso e.KeyChar <> "K" AndAlso e.KeyChar <> "L" AndAlso e.KeyChar <> "Z" AndAlso e.KeyChar <> "X" AndAlso e.KeyChar <> "C" AndAlso e.KeyChar <> "V" AndAlso e.KeyChar <> "B" AndAlso e.KeyChar <> "N" AndAlso e.KeyChar <> "M" Then
            e.Handled = True
        End If
    End Sub

It has a - z A - Z . -

I'm just trying to add a simple function to the textbox for security that if i only allow 0 - 9 Numbers and i try to put a letter it wont let me i forgot the code so if any can help me ...

Hi
Try this code

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
With Me.Text1(1)
KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
End With
With Me.Text1(2)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
End If
End With
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.