How can i check whether the text box is numeric or not?
Because i want to do validation.
but i tried many style still cannot work.

Recommended Answers

All 6 Replies

The isNumeric function is probably the easiest solution. It returns a boolean value indicating whether the input can be parsed to a number.

You could capture the KeyPress Event of the TextBox and allow the user to only enter what you want. You check the value of the KeyPressEventArgs. I usually use it so I don't have to code the ooops you didn't enter the proper value sub/functions. There is also a nice RegEx pattern you can use to match a good value when the user is finished. Let me know if you are interested.

In the key press event of the text box try writing the below code....it will allow user to enter only number and when the user will enter alphabet or any other characters it wont allow user to enter it....

 'accepts only numbers
If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
      e.Handled = True
End If
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
      e.Handled = False
End If

i've solved the problem already, thanks for the helping & suggestions. :)

@gahhon - You must have to post the solution here so other members will benefit from your question/answer.

IsNumeric(txtPostCode.Text) = False


If IsNumeric(txtPostCode.Text) = False Then
    'Do The Validation
End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.