Christoph Christoph - 6 months ago 18
Vb.net Question

how to only allow digits and dots in textbox vb.net

i'm wondering how i can get my textbox to only accept digits and dots. like:

123.45
or 115
or 218.16978

etc..

i allready got the following code:

Private Sub TxtHStof_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtHStof.KeyPress
e.Handled = Not Char.IsDigit(e.KeyChar)

End Sub


But that only allows digits without the dots.
How can i change the code so it does allows the dots aswell, but nothing else. (copy paste doesn't matter since it won't be an issue)

Thanks a lot

Answer
e.Handled = Not (Char.IsDigit(e.KeyChar) OR e.KeyChar=".")
Comments