textbox accept only digits

Posted by hiba salem on Stack Overflow See other posts from Stack Overflow or by hiba salem
Published on 2010-03-27T20:13:57Z Indexed on 2010/03/27 20:33 UTC
Read the original article Hit count: 172

Filed under:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress


    Dim allowedChars As String = "0123456789$,"

    If allowedChars.IndexOf(e.KeyChar) = -1 Then
        ' Invalid Character
        e.Handled = True




    End If
End Sub

this code accept only digits and its working like a charm but if i typed a wrong number its not allowing me to use the delete or the backspace on the keyboard how to solve this problem ?

© Stack Overflow or respective owner

Related posts about vb.net