customvalidator 始终 isvalid=true
我有一个自定义验证器,用于检查输入的日期是否有效。但它始终是真实的,导致它不发射。我曾经有一个 comaprevalidator 和 daterange 但它不会工作,因为当页面刷新时,它会验证出生日期并在它是时说无效。所以我将其更改为 customvalidator 希望我能找到运气。
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please enter MM/DD/YYYY format. Invalid Date 01/01/1901 to 12/31/9999"
ControlToValidate="txtAccusedDOB" SetFocusOnError="True" ClientValidationFunction="ServerValidation1" Display="Static">
<asp:Image ID="Image125" runat="server" ImageUrl="~/images/validatearrow.png" />
</asp:CustomValidator>
<ajaxToolkit:ValidatorCalloutExtender
runat="Server" ID="ValidatorCalloutExtender5" TargetControlID="CustomValidator1" Width="250px" HighlightCssClass="highlight"
CssClass="CustomCalloutStyle" PopupPosition="Right" WarningIconImageUrl="~/images/001_11.png"
CloseImageUrl="~/images/001_05.png" />
<asp:TextBox ID="txtAccusedDOB" runat="server" Style="text-transform: uppercase" onkeydown="TrapEnterKey()"
Width="70px" TabIndex="85">
</asp:TextBox>
这是java脚本。它总是显示alert("test" + argument.Value.toString()); try catch 不起作用。
function ServerValidation1(source, arguments)
{
try{
var x= new Date();
x = Date.parse(arguments.Value.toString())
arguments.IsValid = true;
alert("test" + arguments.Value.toString());
}
catch(Error r)
{
arguments.IsValid = false;
alert("test OUt" + r.toString());
}
有没有更简单的方法来检查输入的日期是否有效。我已经为此苦苦挣扎好几天了。谢谢。
I have a custom validator for checking if date enetred is valid. but it is always true that makes it not firing. I used to have a comaprevalidator and daterange but it won't work coz as page refreshes, it validates the date of birth and says invalid when it is. So I changed it to customvalidator hoping I will find luck.
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please enter MM/DD/YYYY format. Invalid Date 01/01/1901 to 12/31/9999"
ControlToValidate="txtAccusedDOB" SetFocusOnError="True" ClientValidationFunction="ServerValidation1" Display="Static">
<asp:Image ID="Image125" runat="server" ImageUrl="~/images/validatearrow.png" />
</asp:CustomValidator>
<ajaxToolkit:ValidatorCalloutExtender
runat="Server" ID="ValidatorCalloutExtender5" TargetControlID="CustomValidator1" Width="250px" HighlightCssClass="highlight"
CssClass="CustomCalloutStyle" PopupPosition="Right" WarningIconImageUrl="~/images/001_11.png"
CloseImageUrl="~/images/001_05.png" />
<asp:TextBox ID="txtAccusedDOB" runat="server" Style="text-transform: uppercase" onkeydown="TrapEnterKey()"
Width="70px" TabIndex="85">
</asp:TextBox>
here's the java script. it always shows the alert("test" + arguments.Value.toString()); The try catch is not working.
function ServerValidation1(source, arguments)
{
try{
var x= new Date();
x = Date.parse(arguments.Value.toString())
arguments.IsValid = true;
alert("test" + arguments.Value.toString());
}
catch(Error r)
{
arguments.IsValid = false;
alert("test OUt" + r.toString());
}
is there a simpler way to check if date entered is valid. I have been struggling on this for days already. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论