Is it possible to override jquery.validates various validation methods?

I would like to override the jquery validation plugin "number" validation.

This part:

// http://docs.jquery.com/Plugins/Validation/Methods/number
number: function(value, element) {
    return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
},

I did a few searches, but all I could find was how to redefine the messages (which I had already done) and how to navigate to the main jQuery functions that pointed me in that direction ...

$.fn.validate.prototype.methods.number = function (value, element) {
    return this.optional(element) || /^-?\d+(?:\,\d+)?$/.test(value);
};

Using this code, I get the following error:

$. fn.validate.prototype.methods is undefined

Am I missing something? Or am I trying to do the impossible?

If this is not possible, suggestions on an alternative way to change this functionality, without the need to add custom validators in each field with numbers in my application, would be most welcome!

Thank!

+5
1

, , .

$.validator.addMethod("number", function(value, element) {
    return this.optional(element) || /^-?\d+(?:\,\d+)?$/.test(value);
});
+15

All Articles