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.
I will explain in the next articles about MVC4 Razor :Routing or Set StartUp page in MVC4 with example,How to use sessions using C# ,Validate Date using RegularExpressionValidator in ASP.NET like dd-Mmm-yyyy and dd/mm/yyyy and How to hide the page name in ASP.NET using frameset.
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> to
<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.
No comments:
Post a Comment