My Thoughts & Views

String Date Validator in C#

Posted on: March 26, 2007

Simple string date validator.

I am a big fan of maintaining a library of simple and clean helper methods. Here is a simple and clean way to verify if a string formatted date is a valid date. This allows you to encapsulate the exception handling making it easy to use and very readable – another important coding practice.

private static bool IsDate(string sDate)
DateTime dt;
bool isDate = true;

dt = DateTime.Parse(sDate);
isDate = false;

return isDate;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: