Validate Value As Numeric

Test passed values to see if they are numeric or not using the TryParse method on the Double data type.
  1. public static bool IsNumeric(string NumToValidate)
  2. {
  3.  if (HasValue(NumToValidate))
  4.  {
  5.  double NumTest = new double();
  6.  System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US", true);
  7.  return Double.TryParse(NumToValidate, System.Globalization.NumberStyles.Any, cultureInfo.NumberFormat, out NumTest);
  8.  }
  9.  else
  10.  {
  11.  return false;
  12.  }
  13. }

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top