Your Ad Here

Posted By

krisdb on 08/14/08


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

umang_nine
ddevening


IsDate IsNumeric


 / Published in: C#
 

  1. public static bool IsDate(object o)
  2. {
  3. bool result;
  4.  
  5. try
  6. {
  7. DateTime myDT = DateTime.Parse(o.ToString());
  8. result = true;
  9. }
  10. catch (FormatException e)
  11. {
  12. result = false;
  13. }
  14.  
  15. return result;
  16. }
  17.  
  18.  
  19. public static bool IsNumeric(string strNumber)
  20. {
  21. if (HasValue(strNumber))
  22. {
  23. double dummyOut = new double();
  24. System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US", true);
  25.  
  26. return Double.TryParse(strNumber, System.Globalization.NumberStyles.Any, cultureInfo.NumberFormat, out dummyOut);
  27. }
  28. else
  29.  
  30. return false;
  31. }

Report this snippet  

You need to login to post a comment.