I cannot say that I would use regular expressions to check if a string is a numeric value. Slow and hard for such a simple process. I would just run a line one character at a time until I enter an invalid state:
public static bool IsNumeric(string value) { bool isNumber = true; bool afterDecimal = false; for (int i=0; i<value.Length; i++) { char c = value[i]; if (c == '-' && i == 0) continue; if (Char.IsDigit(c)) { continue; } if (c == '.' && !afterDecimal) { afterDecimal = true; continue; } isNumber = false; break; } return isNumber; }
The above example is simple and should do the job for most numbers. However, it is not sensitive to culture, but it must be strong enough to make it sensitive to culture.
source share