---
title: "Date Validation in C Sharp .NET"  
description: "Here I’m going to demonstrate how to validate date entered as string. All we have to do is to split the date string at’/’. The date provided should be"  
author: "Anonymous User"  
published: 2010-07-22  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/55/date-validation-in-c-sharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Date Validation in C Sharp .NET

Here I’m going to demonstrate how to validate date entered as string. All we have

to do is to split the date string at’/’. The date provided should be in MM/DD/YYYY

format.

##### Example

```
private void btnValidate_Click(object sender, EventArgs e)        {//this is store whether data is valid or not.            bool b;//spliting and storing in date array of string type.            string[] date = txtDate.Text.Split('/');//checking whether year is less than 2010 if true then other validations are //checked else value of b will be set to
false.                       if (Convert.ToInt32(date[2]) <= 2010)            {//passing entered date to DateTimeconstructor. If format is correct then the //code will execute otherwise exception will be raise and
catched by catch //block which will set
value of b to false                try                {DateTime check = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]));                                      b= true;                }                catch                {                    b= false;                }            }            else                b= false;//displaying message according to value of b.            if (b)                MessageBox.Show("Valid date");            else                MessageBox.Show("Date Invalid");        }
```

![Date Validation in C Sharp .NET](https://www.mindstick.com/mindstickarticle/080a1bde-b549-4c10-af94-8701026f78ab/images/010c1152-98e4-4c80-bf7a-d4ff60e1fd36.png)![Date Validation in C Sharp .NET](https://www.mindstick.com/mindstickarticle/080a1bde-b549-4c10-af94-8701026f78ab/images/bd266a9a-23f7-49d3-88f5-ff9f5e855efb.png)\

---

Original Source: https://www.mindstick.com/articles/55/date-validation-in-c-sharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
