验证日期字段时出错 [英] Getting error while validating date field

查看:68
本文介绍了验证日期字段时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了比较验证器和范围验证器验证日期字段,但是当我输入13/20/11或20/20/24时出现错误:转换日期时出错 Plzz帮助



I have used compare validator and range validator to validate date field but when i enter 13/20/11 or 20/20/24 i got error : Error while converting datetimePlzz help

<tr>
            <td><b>Re-Contact Date :</b> </td>
            <td><asp:TextBox ID="txtReminderDate" runat="server" Width="70px" />
            <asp:CompareValidator ID="cvReminderDate" ValidationGroup="a" runat="server" ControlToValidate="txtReminderDate" Type="Date" ErrorMessage="Please Enter Valid Date" Display="None" Operator="DataTypeCheck" SetFocusOnError="true"></asp:CompareValidator>
            <asp:RangeValidator runat="server" ID="rvReminderDate" Type="Date" ValidationGroup="a"  ControlToValidate="txtReminderDate" MaximumValue="01/01/9999" MinimumValue="01/01/1900" ErrorMessage="Reminder date can not less then 01/01/1900" Display="None" SetFocusOnError="True" />
            <asp:RequiredFieldValidator ID="rfvReminderDate" ValidationGroup="a" runat="server" ErrorMessage="Please Enter Date." Display="None" SetFocusOnError="true" ControlToValidate ="txtReminderDate"></asp:RequiredFieldValidator>
            </td>
          </tr>

推荐答案

你需要使用正则表达式验证器来验证输入字符串作为日期然后比较和范围验证将根据你的计划工作。
u need to use regex validator as well to validate the input string as date then the compare and range validation would work according to your plans.


当你在文本框中输入日期时间。您的验证器开始将此文本转换为日期时间,然后将比较您的最小值和最大值的日期时间。

输入错误的日期时间。 Validator开始将其转换为日期。比较之前。

所以当你输入 13/20/11或20/20/24 错误的日期时间时。你在比较之前得到了错误。
When you enter a datetime inside textbox. Your validator start to convert this text to date time and then that datetime will be compared for your min and max value.
When you enter Wrong datetime. Validator starts to convert that into date. before comparing.
So when you enter 13/20/11 or 20/20/24 which is wrong date time. you got the error before comparison.


这篇关于验证日期字段时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆