日期验证在 ASP.NET 中无法正常工作

问题描述 投票:0回答:1

这是我面临“无效日期”问题的代码:

enter image description here

enter image description here

我尝试使用日历控件选择

mm/dd/yyyy
格式的日期,并使用正则表达式验证该控件。但它显示“无效日期”错误消息。

c# asp.net validation calendar
1个回答
0
投票

这是代码:

    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtInvoiceDate"
        ValidationExpression="(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/]\d{4}"
        ErrorMessage="Invalid format Valid format is MM/dd/yyyy" ForeColor="Red"
        Display="Dynamic" ValidationGroup="Submit" />
    <asp:RequiredFieldValidator ID="rfvInvoiceDate" runat="server" ErrorMessage="Enter Invoice of Date"
        Text="*" ControlToValidate="txtInvoiceDate" ValidationGroup="Submit"></asp:RequiredFieldValidator>
    <asp:RequiredFieldValidator ID="rfvInvoiceDateS" runat="server" ErrorMessage="Enter Invoice of Date"
        Text="*" ControlToValidate="txtInvoiceDate" ValidationGroup="Confirm"></asp:RequiredFieldValidator>
    <asp:RangeValidator ID="rv_txtInvoiceDate" runat="server" ControlToValidate="txtInvoiceDate" ErrorMessage="Invalid Date" 
        Type="Date" MinimumValue="01/01/1990" MaximumValue="01/01/2090" ForeColor="Red" Display="Dynamic" 
        ValidationGroup="Confirm"> </asp:RangeValidator>
</ItemTemplate>

© www.soinside.com 2019 - 2024. All rights reserved.