We help IT Professionals succeed at work.

regular expression for dd/mm/yyyy in C#.net

praveen1981
praveen1981 asked
on
Hi

I want to  check the given data is in the Regular expression  dd/mm/yyyy  format or not using c#.net

Can you please suggest.
Comment
Watch Question

Use this regular expression

[0-3]{0,1}[0-9]\.[0-1]{0,1}[0-9]\.[0-9]{4,2}
Project Lead
BRONZE EXPERT
Top Expert 2011
Commented:
Try this

^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$
Try this
Java script
<script type="text/javascript" language="javascript">
    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))))$/;
        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)) {
            alert("Valid");
        } else {
            alert("Invalid!");
        }
    }

Open in new window


asp.net textbox and button
<asp:TextBox ID="txtDateValidation" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit it" OnClientClick="javascript:CheckDate();" />

Open in new window

Deepu AbrahamR & D Engineering Manager

Commented:

Author

Commented:
It solved the Problem

Explore More ContentExplore courses, solutions, and other research materials related to this topic.