I looked all over the net, Google it and found a lot of examples, most of them worked only partially.
How can I make a text box to accept numbers only?
Example:
1234 or 12.34, but NOT 123.45.67
And allow BackSpace and Delete keys to correct mistakes?
In VB6 I used:
Code:
Private Sub txtTextBox_KeyPress(KeyAscii As Integer)
If (KeyAscii > 47 And KeyAscii < 58) Or KeyAscii = 8 Then
[green]'Only numbers are entered - it is OK[/green]
Else
KeyAscii = 0
End If
End Sub
And I found this in VB.NET, but is not complete:
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress
If Not Char.IsNumber(e.KeyChar) Then
e.Handled = True
End If
End Sub
Have fun.
---- Andy