Visual Basic 2008 Tutorials
www.reflectionforbrain.com

 

Back | Index

Allow Numbers only in TextBox

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

        If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 _

        AndAlso Not IsNumeric(e.KeyChar) Then

            MessageBox.Show("Please enter numbers only")

            e.Handled = True

        End If

    End Sub

You can also remove numbers after user enter numbers in a text box: click here