繁体   English   中英

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>

您可以使用http://forums.asp.net/t/1480183.aspx中定义的asp:RegularExpressionValidator使用asp:RegularExpressionValidator in asp:RegularExpressionValidator

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM