# Regular expression for validating Date format dd/MM/yyyy[Answered] RSS

## 8 replies

Last post Jun 10, 2010 04:16 AM by santosh.patro

• Rameezwaheed

Contributor

2633 Points

1770 Posts

### Regular expression for validating Date format dd/MM/yyyy

Apr 15, 2009 02:47 AM|Rameezwaheed|LINK

Hi,

What would be regular Expression for validating Date format like dd/MM/yyyy.?

Best Regards

life is name of learning!
Mark as an answer if it helps
• venkatu2005

All-Star

20763 Points

6706 Posts

### Re: Regular expression for validating Date format dd/MM/yyyy

Apr 15, 2009 03:27 AM|venkatu2005|LINK

#### Rameezwaheed

What would be regular Expression for validating Date format like dd/MM/yyyy.?

Regex: matches a date in dd/mm/yyyy format

^(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\/02\/(19|20)(([02468][048])|([13579][26]))))\$

|

Thanks.
• yasserzaid

Star

9691 Points

2187 Posts

### Re: Regular expression for validating Date format dd/MM/yyyy

Apr 15, 2009 03:32 AM|yasserzaid|LINK

Hi

Use this following Regular Expression Details, This will support leap year also.

^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))\$

Matches
[29/02/2000], [30/04/2003], [01/01/2003]

Non-Matches
[29/02/2001], [30-04-2003], [1/1/1899]

or check this link http://www.codeproject.com/KB/aspnet/LengthValidation.aspx

Good Luck

• shashankgwl

Star

11864 Points

3618 Posts

### Re: Regular expression for validating Date format dd/MM/yyyy

Apr 15, 2009 03:35 AM|shashankgwl|LINK

google will give you 20400 results for your query

SHASHANK BHIDE

blog
• susain

Participant

1638 Points

715 Posts

### Re: Regular expression for validating Date format dd/MM/yyyy

Apr 15, 2009 04:17 AM|susain|LINK

Hi Rameez,

This is good site where you can find regular expressions to use for future http://regexlib.com/Default.aspx

Thanks,

Farooq

• miguelangel1...

Member

6 Points

90 Posts

### Re: Regular expression for validating Date format dd/MM/yyyy

Apr 15, 2009 04:45 AM|miguelangel197|LINK

Hi,

There is a very simple and nice way using ajax, ASP.NET AJAX MaskedEdit . Check this link http://www.asp.net/learn/ajax-videos/video-131.aspx

• Rameezwaheed

Contributor

2633 Points

1770 Posts

### Re: Regular expression for validating Date format dd/MM/yyyy

Apr 15, 2009 08:01 AM|Rameezwaheed|LINK

Thanks for all for shairing Ideas ,

I got it working and surely marked the post(s) as answer which helped me .

once again thanks for all.

Best Regards

life is name of learning!
Mark as an answer if it helps
• vizvin

None

0 Points

1 Post

### Re: Regular expression for validating Date format dd/MM/yyyy

Nov 10, 2009 12:33 AM|vizvin|LINK

I liked the leap year support.. Could you help me with a similar one?..my date format would be either "ddMMyyyy" or "MMddyyyy"

• santosh.patr...

Member

1 Points

62 Posts

### Re: Regular expression for validating Date format dd/MM/yyyy

Jun 10, 2010 04:16 AM|santosh.patro|LINK

Hi YasserZaid,

Your suggestion for date validate worked excellent.

The sample Javascript with details is as mentioned below:

function

}

}

}

}

isValidDate(sText) {var re = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))\$/;return re.test(sText);function CheckDate() {var oInput1 = document.getElementById("<%=txtDateValidation.ClientID %>");if (isValidDate(oInput1.value)) {"Valid");else {"Invalid!");

<

asp:TextBox ID="txtDateValidation" runat="server"></asp:TextBox>

<br />

<asp:Button ID="btnSubmit" runat="server" Text="Submit it" OnClientClick="javascript:CheckDate();" />

Thanks & Regards,

Santosh