Allowing Numbers only in Textbox Using VB.Net

0
194

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.
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    2. If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then
    3. MessageBox.Show("Please enter numbers only")
    4. e.Handled = True
    5. End If
    6. End Sub
  • After that, Click F5 to run the program.
    Output:

 

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:

 

 

 

 

 

Facebook Comments
(Visited 208 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here