Reputation: 553
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?
Upvotes: 1
Views: 753
Reputation: 3976
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);
}
Upvotes: 1