In this tutorial I will show you how you can validate string length i.e. maximum and minimum characters in jQuery
For this operation we will use ASP.NET Custom validator
First in our markup we need to create a Custom Validator
<asp:CustomValidator ID="CustomPasswordRangeValidator"
ClientValidationFunction="ClientValidate" ControlToValidate="Password" runat="server"></asp:CustomValidator>
Now we will define a method in javascript this function will contain all the validation
For this operation we will use ASP.NET Custom validator
First in our markup we need to create a Custom Validator
<asp:CustomValidator ID="CustomPasswordRangeValidator"
ClientValidationFunction="ClientValidate" ControlToValidate="Password" runat="server"></asp:CustomValidator>
Now we will define a method in javascript this function will contain all the validation
function ValidateUserName(source, clientside_arguments) {
//Test whether the length of the value is more than 6 characters
if (clientside_arguments.Value.length >= 4 && clientside_arguments.Value.length <= 10) {
clientside_arguments.IsValid = true;
}
else {
clientside_arguments.IsValid = false
source.innerHTML = "UserName must be between 5 to 10 characters";
};
this function check if the string length is greater than 4 and less than 10 than it will be allowed.
else we will set a custom error message
I hope it was informative for you and I would like to Thank you for reading
No comments:
Post a Comment