We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

krisdb on 08/14/08


Tagged


Versions (?)


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.