Software Engineer, Equity Strategist, Polymath.
Posts tagged Textbox that accepts only numbers
Make a Textbox that accepts only numbers
17 years
by Ray Tawil
in Visual Basic.Net
[codesyntax lang=”vbnet” highlight_lines=””]
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Const pstr As String = “0123456789”
If pstr.IndexOf(e.KeyChar) = -1 Then
e.Handled = True
End If
End Sub
[/codesyntax]
If you want to add “.” for exmaple to the combination you can change first line to [codesyntax lang=”vbnet” highlight_lines=””]
Const pstr As String = "0123456789"
[/codesyntax]