Sunday 5 June 2016

Allow Numbers only in a TextBox - Visual Basic .NET



So the code for allowing only numbers in the textbox for employee ID is:

Just copy the code in the box given below:
Private Sub TextBox1_KeyPress(ByVal sender As ObjectByVal 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

The Result:



1 comment: