I have a need for users to be able to create partial URLs without needing to type the full URL each time.
For example, say I plan on the url being www.example.com/areas/{userinput}/home
. I want the user to be able to enter some text in a text box and I want to validate that it is a valid URL.
The URL validator functions like this:
url: function(value, element) {
return this.optional(element) || /giantregex/.test(value);
}
I've attempted adding a validation method to the validator via the following:
$.validator.addMethod("exturl", function(value) {
return $.validator.methods.url.call($.validator, "http://www.example.com/areas/" + value + "/home");
});
However, when the form is validated and my extension is called, I keep getting this error:
Uncaught TypeError: Object function (d,a){this.settings=b.extend(true,{},b.validator.defaults,d);this.currentForm=a;this.init()} has no method 'optional'
optional
looks to be a method on the $.validator
object but I can't figure out how to call the validator url method.