To check if a string is a valid number we either have to use the Try..Catch..Finally with Integer.Parse or try Double.TryParse.
I just saw a method using regular expressions sometime backWe can call this function like thisVB Code:
Public Function IsNumeric(ByVal inputString As String) As Boolean Dim _isNumber As System.Text.RegularExpressions.Regex = New _ System.Text.RegularExpressions.Regex("(^[-+]?\d+(,?\d*)*\.?\d*([Ee][-+]\d*)?$)|(^[-+]?\d?(,?\d*)*\.\d+([Ee][-+]\d*)?$)") Return _isNumber.Match(inputString).Success End FunctionVB Code:
If isNumeric("1234") Then MessageBox.Show("String is Numeric") Else MessageBox.Show("String is not Numeric") End If
Edit--
I have got this RegEx from Internet which checks almost all the possibilities.




Reply With Quote