Easy way to check numeric ,date in c#

Description :


We can pass date as string into this function, if it's not a valid date means
it will return false otherwise true.same like numeric also.we can check other
datatype also this way.

Here is the code :

public static bool IsDate(string strdt)
{
try
{
if (strdt.Trim() != "")
{
DateTime dt = Convert.ToDateTime(strdt);
}
return true;
}
catch
{
return false;
}
}


public static bool IsNumeric(string numberString)
{
try
{
if (numberString.Trim() != "")
{
double num = Convert.ToDouble(numberString);
}
return true;
}
catch
{
return false;
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: