Only allow Numbers in a TextBox Control in VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Code snippet to allow only numbers in a textbox.

Put the snippet below in the Textbox_Keypress Event.

        'This will simply check the Keychar that was pressed and will only allow numbers
        'to be typed‘in the TextBox control.
        'Put in the ‘TextBox_KeyPress’ event.
        If Not Char.IsNumber(e.KeyChar) Then

            e.Handled = True

        End If

Leave a Reply