I'm trying to add a jQuery validator rule dynamically and it's not working. It doesn't throw any errors but doesn't trigger the validation.
Here's the js:
$(document).ready(function () {
$.validator.addMethod("TIME", function (value, element) {
var re = new RegExp(regexp);
console.debug("Validating " + value);
return this.optional(element) || re.test("^*(1[0-2]|[1-9]):[0-5][0-9] *(a|p|A|P)(m|M)*$").test(value);
}, "Time is invalid: Please enter a valid time.");
$("input[id *= '_timepicker']").rules("add", "TIME");
});
Any idea what's wrong?
EDIT:
Now I get an error: invalid quantifier *(1[0-2]|[1-9]):[0-5][0-9] (a|p|A|P)(m|M)$
Here's the relevant js:
rules:{"special.Hours.FridayHours1.close":{ regExp: /^*(1[0-2]|[1-9]):[0-5][0-9] *(a|p|A|P)(m|M)*$/ }
Here's the complete validate function: