Asp.net自定义验证器 [英] Asp.net custom validator
本文介绍了Asp.net自定义验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在我的代码后面使用自定义验证器使用ASP.NET C#
i在我的应用程序中返回以下代码
实际上代码在我的结束时工作正常,但错误的方式
但是我需要以下选项,比如我们,
char应该是min 5到10
我的代码是:
hi all,
am using custom validator on my code behind using ASP.NET C#
i have return below code in my application
actually the code was working fine on my end but the wrong way
but i need the below option such us,
the char should be min 5 to 10
my code is:
server side code:
protected void TextValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = (args.Value.Length == 5);
}
client side code:
<asp:textbox id=TextBox1 runat="server"></asp:textbox>
<asp:CustomValidator id="CustomValidator1" runat="server"
OnServerValidate="TextValidate"
ControlToValidate="TextBox1"
ErrorMessage="the char should be min 5 to 10.">
</asp:CustomValidator>
所以请看看我的代码,
i尝试了很多其他方式,但我不能。
感谢所有
so please have a look at my code,
i have tried many other way but i cant.
thanks to all
推荐答案
您可以申请以下代码:
You can apply below code :
<asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
<asp:regularexpressionvalidator display="Dynamic" controltovalidate="TextBox1" id="RegularExpressionValidator3" validationexpression="^[\s\S]{5,10}
runat = server errormessage = 最少5个字符和最多10个字符。 xmlns:asp = #unknown > < / asp:regularexpressionvalidator >
" runat="server" errormessage="Minimum 5 and Maximum 10 characters required." xmlns:asp="#unknown"></asp:regularexpressionvalidator>
您是否尝试过以下声明。< br $>
Have you tried below statement.
args.IsValid = (args.Value.Length >= 5 && args.Value.Length <= 20);
这篇关于Asp.net自定义验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文