.NET testing a string for numeric value
algorithm, c#, regex
Solution
Just off of the top of my head - why not just use `double.TryParse` ? I mean, unless you really want a regexp solution - which I'm not sure you really need in this case :)
Problem
Consider the need for a function in C# that will test whether a string is a numeric value. The requirements: - must return a boolean. - function should be able to allow for whole numbers, decimals, and negatives. - assume no `using Microsoft.VisualBasic` to call into `IsNumeric()`. Here's a case of reinventing the wheel, but the exercise is good. Current implementation: ``` //determine whether the input value is a number public static bool IsNumeric(string someValue) { Regex isNumber = new Regex(@"^\d+$"); try { Match m = isNumber.Match(someValue); return m.Success; } catch (FormatException) {return false;} } ``` Question: how can this be improved so that the regex would match negatives and decimals? Any radical improvements that you'd make?