This tutorial is all about Allowing Numbers only in Textbox Using VB.Net. With this tutorial about Allowing Numbers only in Textbox Using VB.Net we set a restriction on textbox which allow us to enter only numbers. So let’s get started:
- First is open the Visual Basic, Select File on the menu, then click New and create a new project.
- Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK
- Then design your form like this just like what I’ve shown you below
Select a Textbox and label.
- Add this code to the TextBox KeyPress event.
[vbnet]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
- After that, Click F5 to run the program.
If you have any comments or suggestions about on Allowing Numbers only in Textbox Using VB.Net. Please feel free to contact our webpage.
Download Allowing Numbers only in Textbox Using VB.Net Code here
Articles you might like to read also: