Check the numerical value

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
How to check the input of textbox.text whether is a numerical value or not?
 
VB.NET:
microsoft.visualbasic.isnumeric(textbox.text)
I know it's part of the 'old' visual basic, but it really is a very efficient function.
 
You should use Double.TryParse. It was specifically created to improve the perfromance of IsNumeric. If IsNumeric is going to call it anyway then why not do it yourself? It also gives you the ability to specify the types of numbers that are acceptable, like only positive, only integers or only currency.
VB.NET:
        Dim num As Double

        If Double.TryParse(Me.TextBox1.Text, Globalization.NumberStyles.Float, Nothing, num) Then
            MessageBox.Show("You entered the number " & num.ToString())
        Else
            MessageBox.Show("Please enter a valid number.")
        End If
 
Back
Top