Hi Guys!

I coded my textbox to be only type in numeric numbers. But the backspace doesn't work when I run the program anymore, Can't delete what has typed in the textbox.

Anyone can help me?

Here is my code

Private Sub AmountTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles AmoutTextBox.KeyPress

        Dim allowedChars As String = "0123456789"

        If allowedChars.IndexOf(e.KeyChar) = -1 Then
            ' Invalid Character
            e.Handled = True
        End If

    End Sub

Recommended Answers

All 2 Replies

Member Avatar for saravind84

Hi,

I have modified the code to allow back space. Please find the code below.

Dim allowedChars As String = "0123456789"
        If e.KeyChar <> ControlChars.Back Then
            If allowedChars.IndexOf(e.KeyChar) = -1 Then
                ' Invalid Character
                e.Handled = True
            End If
        End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.