Check string for only digits and one optional decimal point.

c#, numeric

Solution

double n;
if (Double.TryParse("128337.812738", out n)) {
  // ok
}

works assuming the number doesn't overflow a double

for a huge string, try the regexp:

if (Regex.Match(str, @"^[0-9]+(\.[0-9]+)?$")) {
  // ok
}

add in scientific notation (e/E) or +/- signs if needed...

Problem

I need to check if a string contains only digits. How could I achieve this in C#? ``` string s = "123" → valid string s = "123.67" → valid string s = "123F" → invalid ``` Is there any function like IsNumeric?

Original source