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 thisCode:private bool isNumeric(string stringToCheck) { System.Text.RegularExpressions.Regex _isNumber = new System.Text.RegularExpressions.Regex (@"(^[-+]?\d+(,?\d*)*\.?\d*([Ee][-+]\d*)?$)|(^[-+]?\d?(,?\d*)*\.\d+([Ee][-+]\d*)?$)"); return _isNumber.Match(stringToCheck).Success; }Code:if (isNumeric("1234")) { //string is a valid number } else { //string is not a valid number }




Reply With Quote