JQuery Validator Custom Method

Could you take a look at this http://jsbin.com/osolo/ , please?

If you enter a letter in Min Age, not a number, then click to confirm it using the jquery validator, using a regular expression in a custom validation method, this works, but now I want to make it more dynamic.

In the custom validation method, the line

var data = $(element).metadata(); 

captures metadata from the item being checked, what I would like to do is use

data.validateOptions.regex

as a regular expression for checking with (I don’t see that this is a problem), what I see is the problem, is that if the field does not check, but does not use the message that is provided when called

jQuery.validator.addMethod(name, method, message)

I would like to use

data.validateOptions.message

, - ?

OneShot

+1
2

, Alex , JS.

. Alex, , ( ), , , addmethod. :

(function() {
    var data = {};
    var messager = function() {
        return data.validateOptions.message;
    };
    jQuery.validator.addMethod("perorgproperty", function(value, element) { 
        debugger; 
        //alert('testing perorgproperty'); 
        data = $(element).metadata();
        return this.optional(element) || /^\d+$/i.test(value); 
    }, messager);
})();
+1

?

var data = {};
jQuery.validator.addMethod("perorgproperty", function(value, element) { 
    debugger; 
    //alert('testing perorgproperty'); 
    data = $(element).metadata(); 

    return this.optional(element) || /^\d+$/i.test(value); 
}, data.validateOptions.message); 

, message ?

0

All Articles