Link to home
Start Free TrialLog in
Avatar of praveen1981
praveen1981Flag for India

asked on

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

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.
Avatar of sachinpatil10d
sachinpatil10d
Flag of India image

Use this regular expression

[0-3]{0,1}[0-9]\.[0-1]{0,1}[0-9]\.[0-9]{4,2}
ASKER CERTIFIED SOLUTION
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of praveen1981

ASKER

It solved the Problem