- In this exercise you will learn one of the methods of validating inputs at field level
- Add a new form to project. Name it as frmTextboxvalid.
- Place a Label and a TextBox. Name the textbox as txtNumbers.
- Click at "View" and then at "Code" to enter the code window.
- Click at the combo box on the left side and select txtNumbers.
- Click at the combo box on the right side and select KeyPress event.
- Then write the following code.
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
- Run the Application.