Tuesday 26 November 2013

How to Compare Start Date and End Date and Validate in YYYY-MM-DD Format in ASP.NET

Hi Friends, in this article I will explain about How to Compare Start Date and End Date and Validate in YYYY-MM-DD Format in ASP.NET.
In ASP.NET:
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
    <title>How to Compare Start Date and End Date and Validate in YYYY-MM-DD Format in ASP.NET</title>
    <style type ="text/css" >
    .color
    {
        color:Red;
    }
    </style>


</head>
<body>
    <form id="form1" runat="server">
    <div>  
     Start Date/End Date:<asp:TextBox ID="txtStartDate" runat="server" MaxLength="10"></asp:TextBox>&nbsp; to &nbsp;
     <asp:TextBox ID="txtEndDate" runat="server" MaxLength="10"></asp:TextBox>     <br />
     <asp:RegularExpressionValidator ID="RegStartDate" runat="server" CssClass ="color"  ValidationExpression="(19|20|21)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])" ControlToValidate="txtStartDate" ErrorMessage="Enter a  valid Start date e.g (yyyy-mm-dd) ."></asp:RegularExpressionValidator>
     <asp:RegularExpressionValidator ID="RegEndDate" runat="server"  CssClass ="color"  ValidationExpression="(19|20|21)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])" ControlToValidate="txtEndDate" ErrorMessage="Enter a valid End date e.g (yyyy-mm-dd) ."></asp:RegularExpressionValidator>     <br />
  <asp:CompareValidator id="cvtxtStartDate" runat="server" CssClass ="color"
       controltocompare="txtEndDate"
       cultureinvariantvalues="true"
       display="Dynamic"
       enableclientscript="true"
       controltovalidate="txtStartDate"
       errormessage="Please ensure that the End Date is greater than Start Date."
       type="Date"
       setfocusonerror="true"
       operator="LessThanEqual"
       text="Please ensure that the End Date is greater than Start Date."/><br />
<asp:Button ID="btnSubmit" runat ="server" Text="Submit"  />
    </div>
    </form>
</body>
</html>


The output of the above code as shown in the below figure.
"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook pageAspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter  on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on  RSSfeed Aspdotnet-Kishore for free updates directly to your Email inbox . Watch my blog  for more articles."

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.