asp:CompareValidator 与 d/M/yyyy 以外的其他日期格式?

asp:CompareValidator with other date formats other than d/M/yyyy?

我将 VS2005 与 ASP.net 2 和 SQL Server 2005

一起使用

我想使用 asp:CompareValidator 来验证文本框日期字段,但我希望它同时验证 d/M/yyyy 格式(验证程序的默认值)和自定义日期格式,如 dd MM yyyy甚至 dd MMMM yyyy。

是否可以或我必须使用 CustomValidator?

这是我的代码

                                <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>

您可以使用 asp:RegularExpressionValidator 中定义的 http://forums.asp.net/t/1480183.aspx?Using+CustomValidator+to+validate+Date+Format+in+dd+MM+yyyy

您唯一找到的是可以验证多种日期格式的正则表达式。