1

I am trying customvalidator control of asp.net but the problem is that it is not calling the javascript function. However it is calling the server side version of the validation method..

          <asp:CustomValidator  EnableClientScript="true"  
                ID="RegularExpressionValidatorFixedNames" runat="server"  ControlToValidate="TextBoxChapterName" 
                Text="Name not allowed" Font-Size="XX-Small"
                ValidationGroup="Name" 
                ClientValidationFunction="LQA_Validate"
                onservervalidate="RegularExpressionValidatorFixedNames_ServerValidate">   </asp:CustomValidator>

the javascript function

         function LQA_Validate(sender, args) {
        var re = /(?! My Ls|My As|My Qs).*/ig;
        args.IsValid = re.test(args);
    }

the server side method

          protected void RegularExpressionValidatorFixedNames_ServerValidate(object source, ServerValidateEventArgs args)
{
    Regex regex = new Regex(@"^(?!My Ls|My Qs|My As).*", RegexOptions.IgnoreCase);
    args.IsValid = regex.IsMatch(args.Value);
}

what can be the problem is this problem because of the regex or I am doing some technical mistake?

11
  • I used console.log but the javascript function is called at all.. Commented May 24, 2013 at 16:07
  • what it (console) gives any error like function undefined? Commented May 24, 2013 at 16:08
  • sorry I made mistake in comment it is called Commented May 24, 2013 at 16:09
  • I think some problem with the regex Commented May 24, 2013 at 16:09
  • What is the args variable? The .text() method expects a string, but if its a string primitive you can't assign an .IsValid property to it. Commented May 24, 2013 at 16:09

1 Answer 1

1

The problem is this:

 function LQA_Validate(sender, args) {
    var re = /(?! My Ls|My As|My Qs).*/ig;
    args.IsValid = re.test(args);
}

In re.test(args) you should use re.test(args.Value);

So the code must be:

 function LQA_Validate(sender, args) {
    var re = /(?! My Ls|My As|My Qs).*/ig;
    args.IsValid = re.test(args.Value);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.