Christoph Christoph - 2 years ago 184 Question

how to only allow digits and dots in textbox

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

or 115
or 218.16978


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 Source
e.Handled = Not (Char.IsDigit(e.KeyChar) OR e.KeyChar=".")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download