I am using Asp.Net MVC 3 and I am adding a validator later in the lifecycle through jquery with jquery.validate using [this code][1]:
Thanks to the answer of redsquare I added a method like this:
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var check = false;
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Please check your input."
);
now all you need to do to validate against any regex is this:
$("Textbox").rules("add", { regex: "^[a-zA-Z'.\s]{1,40}$" })
The validation is working fine, but the actual message isn't showing up anywhere... what am I doing wrong? Thank you.