Hi, I want my my input, just numberic allowed.
if user key in alphabet, error message will show up.
How can i do that?!
Please help!

Thanks

IF IT IS RELATED TO A TEXT BOX:

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

If IsNumeric(TextBox1.text) = false then

try
textbox1.text = textbox1.text.substring(0, len(textbox1.text) - 1)
catch ex as exception

textbox1.text = ""

end try

end if

    End Sub

If you generally want to capture a keyboard event (entire form, anywhere), you first need to on formload set:

KeyPreview = True

Then you do something like:

Private Sub Key_Click(ByVal sender as Object, ByVal e as System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

if isnumeric(e.keydata.tostring) = false then


end if

End Sub

If this helped you, mark it as solved and/or give me some reputation points.

there are better to not allowed user to input alphabetic character. So, when user press keyboard keys, u can handled it by code to not allowed them to input alphabetical character.
this following code will not allowed you to input except number :

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
              Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
            e.Handled = True
        End If
        If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
            e.Handled = False
        End If
    End Sub
This article has been dead for over six months. Start a new discussion instead.