[英]asp:CompareValidator with other date formats other than d/M/yyyy?
I am using VS2005 with ASP.net 2 and SQL Server 2005 我将VS2005与ASP.net 2和SQL Server 2005一起使用
I want to use the asp:CompareValidator to validate a text box date field, but I want it to validate both d/M/yyyy format (default of the validator) and custom date formats like dd MM yyyy or even dd MMMM yyyy. 我想使用asp:CompareValidator来验证文本框日期字段,但是我想使用它来验证d / M / yyyy格式(验证程序的默认值)和自定义日期格式,例如dd MM yyyy甚至dd MMMM yyyy。
Is it possible or do I have to use a CustomValidator? 有可能还是我必须使用CustomValidator?
Here is my code 这是我的代码
<asp:TemplateField HeaderText="Date of Birth" SortExpression="StudentDOB">
<InsertItemTemplate>
<asp:TextBox ID="tbDOB" runat="server" Text='<%# Bind("StudentDOB","{0:d/M/yyyy}") %>'></asp:TextBox>
<asp:ImageButton runat="Server" ID="Image1" ImageUrl="~/images/Calendar_scheduleHS.png" AlternateText="Click to show calendar" CausesValidation="False" />
<ajaxToolkit:CalendarExtender PopupButtonID="Image1" Format="d/M/yyyy" TargetControlID="tbDOB" ID="CalendarExtender1" runat="server"></ajaxToolkit:CalendarExtender>
<asp:RequiredFieldValidator ID="rfvDOB" runat="server" ControlToValidate="tbDOB" ErrorMessage="* required">* Required</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="tbDOB" Display="Dynamic" ErrorMessage="Invalid Date" Operator="DataTypeCheck" Type="Date" />
</InsertItemTemplate>
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" />
</asp:TemplateField>
You can use a asp:RegularExpressionValidator
as defined in http://forums.asp.net/t/1480183.aspx?Using+CustomValidator+to+validate+Date+Format+in+dd+MM+yyyy 您可以使用http://forums.asp.net/t/1480183.aspx中定义的
asp:RegularExpressionValidator
使用asp:RegularExpressionValidator
in asp:RegularExpressionValidator
The only thing you have find is a regex that can validate multiple date formats. 您唯一找到的是一个可以验证多种日期格式的正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.