Landers_15
Landers_15

Reputation: 81

Having Text Box accept Numbers Backspace and a Decimal place

I need to make the text box only accept Numbers Decimals and the Backspace. This is what I have so far and it works great for numbers and backspace but I have no idea what to do for periods. So any help would be great.

    Private Sub txtlength_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtlength.KeyPress
    If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
        e.Handled = True
    End If
End Sub

Upvotes: 0

Views: 2074

Answers (1)

SomeNickName
SomeNickName

Reputation: 521

e.Handled = Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = ControlChars.Back Or e.KeyChar = ".")

Upvotes: 1

Related Questions