Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

XML
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>




so please have a look at my code,
i have tried many other way but i cant.

thanks to all
Posted

You can apply below code :

ASP.NET
<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="Minimum 5 and Maximum 10 characters required." xmlns:asp="#unknown"></asp:regularexpressionvalidator>
 
Share this answer
 
Have you tried below statement.

JavaScript
args.IsValid = (args.Value.Length >= 5 && args.Value.Length <= 20);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900