src/jquery.validation.js
function validateRule(value, rule, reversed) {

            // Validate for "data-validation-regex" and "data-validation-regex-reverse"
            if (rule instanceof RegExp) {
                var isValid = rule.test(value);

                if (reversed) {
                    isValid = !isValid;
                }

                if (!isValid) {
                    throw [options.messages['default'], ''];
                }
                return;
            }

            if (options.rules[rule]) {
                if (!options.rules[rule].test(value)) {
                    throw [options.messages[rule], ''];
                }
                return;
            }

            // Validate for comparison "data-validation"
            var comparison = rule.match(options.rules.COMPARISON);

            if (!comparison || comparison.length !== 4) {

                // {debug}
                options.debug && window.Debug.log({
                    'node': node,
                    'function': 'validateRule()',
                    'arguments': 'value: ' + value + ' rule: ' + rule,
                    'message': 'WARNING - Invalid comparison'
                });
                // {/debug}

                return;
            }

            var type = comparison[1],
                operator = comparison[2],
                compared = comparison[3],
                comparedValue;

            switch (type) {

                // Compare input "Length"
                case "L":

                    // Only numeric value for "L" are allowed
                    if (isNaN(compared)) {

                        // {debug}
                        options.debug && window.Debug.log({
                            'node': node,
                            'function': 'validateRule()',
                            'arguments': 'compare: ' + compared + ' rule: ' + rule,
                            'message': 'WARNING - Invalid rule, "L" compare must be numeric'
                        });
                        // {/debug}

                        return false;

                    } else {

                        if (!value || eval(value.length + operator + parseFloat(compared)) === false) {
                            throw [options.messages[operator], compared];
                        }

                    }

                    break;

                // Compare input "Value"
                case "V":
                default:

                    // Compare Field values
                    if (isNaN(compared)) {

                        comparedValue = node.find('[name="' + compared + '"]').val();
                        if (!comparedValue) {

                            // {debug}
                            options.debug && window.Debug.log({
                                'node': node,
                                'function': 'validateRule()',
                                'arguments': 'compare: ' + compared + ' rule: ' + rule,
                                'message': 'WARNING - Unable to find compared field [name="' + compared + '"]'
                            });
                            // {/debug}

                            return false;
                        }

                        if (!value || !eval('"' + encodeURIComponent(value) + '"' + operator + '"' + encodeURIComponent(comparedValue) + '"')) {
                            throw [options.messages[operator].replace(' characters', ''), compared];
                        }

                    } else {
                        // Compare numeric value
                        if (!value || isNaN(value) || !eval(value + operator + parseFloat(compared))) {
                            throw [options.messages[operator].replace(' characters', ''), compared];
                        }

                    }
                    break;

            }

        }
function validateRule(value, rule, reversed) {

            // Validate for "data-validation-regex" and "data-validation-regex-reverse"
            if (rule instanceof RegExp) {
                var isValid = rule.test(value);

                if (reversed) {
                    isValid = !isValid;
                }

                if (!isValid) {
                    throw [options.messages['default'], ''];
                }
                return;
            }

            if (options.rules[rule]) {
                if (!options.rules[rule].test(value)) {
                    throw [options.messages[rule], ''];
                }
                return;
            }

            // Validate for comparison "data-validation"
            var comparison = rule.match(options.rules.COMPARISON);

            if (!comparison || comparison.length !== 4) {

                // {debug}
                options.debug && window.Debug.log({
                    'node': node,
                    'function': 'validateRule()',
                    'arguments': 'value: ' + value + ' rule: ' + rule,
                    'message': 'WARNING - Invalid comparison'
                });
                // {/debug}

                return;
            }

            var type = comparison[1],
                operator = comparison[2],
                compared = comparison[3],
                comparedValue;

            switch (type) {

                // Compare input "Length"
                case "L":

                    // Only numeric value for "L" are allowed
                    if (isNaN(compared)) {

                        // {debug}
                        options.debug && window.Debug.log({
                            'node': node,
                            'function': 'validateRule()',
                            'arguments': 'compare: ' + compared + ' rule: ' + rule,
                            'message': 'WARNING - Invalid rule, "L" compare must be numeric'
                        });
                        // {/debug}

                        return false;

                    } else {

                        if (!value || eval(value.length + operator + parseFloat(compared)) === false) {
                            throw [options.messages[operator], compared];
                        }

                    }

                    break;

                // Compare input "Value"
                case "V":
                default:

                    // Compare Field values
                    if (isNaN(compared)) {

                        comparedValue = node.find('[name="' + compared + '"]').val();
                        if (!comparedValue) {

                            // {debug}
                            options.debug && window.Debug.log({
                                'node': node,
                                'function': 'validateRule()',
                                'arguments': 'compare: ' + compared + ' rule: ' + rule,
                                'message': 'WARNING - Unable to find compared field [name="' + compared + '"]'
                            });
                            // {/debug}

                            return false;
                        }

                        if (!value || !eval('"' + encodeURIComponent(value) + '"' + operator + '"' + encodeURIComponent(comparedValue) + '"')) {
                            throw [options.messages[operator].replace(' characters', ''), compared];
                        }

                    } else {
                        // Compare numeric value
                        if (!value || isNaN(value) || !eval(value + operator + parseFloat(compared))) {
                            throw [options.messages[operator].replace(' characters', ''), compared];
                        }

                    }
                    break;

            }

        }
function validateRule ( value , rule , reversed ) { // Validate for "data-validation-regex" and "data-validation-regex-reverse" if ( rule instanceof RegExp ) { var isValid = rule . test ( value ) ; if ( reversed ) { isValid = ! isValid ; } if ( ! isValid ) { throw [ options . messages [ 'default' ] , '' ] ; } return ; } if ( options . rules [ rule ] ) { if ( ! options . rules [ rule ] . test ( value ) ) { throw [ options . messages [ rule ] , '' ] ; } return ; } // Validate for comparison "data-validation" var comparison = rule . match ( options . rules . COMPARISON ) ; if ( ! comparison || comparison . length !== 4 ) { // {debug} options . debug && window . Debug . log ( { 'node' : node , 'function' : 'validateRule()' , 'arguments' : 'value: ' + value + ' rule: ' + rule , 'message' : 'WARNING - Invalid comparison' } ) ; // {/debug} return ; } var type = comparison [ 1 ] , operator = comparison [ 2 ] , compared = comparison [ 3 ] , comparedValue ; switch ( type ) { // Compare input "Length" case "L" : // Only numeric value for "L" are allowed if ( isNaN ( compared ) ) { // {debug} options . debug && window . Debug . log ( { 'node' : node , 'function' : 'validateRule()' , 'arguments' : 'compare: ' + compared + ' rule: ' + rule , 'message' : 'WARNING - Invalid rule, "L" compare must be numeric' } ) ; // {/debug} return false ; } else { if ( ! value || eval ( value . length + operator + parseFloat ( compared ) ) === false ) { throw [ options . messages [ operator ] , compared ] ; } } break ; // Compare input "Value" case "V" : default : // Compare Field values if ( isNaN ( compared ) ) { comparedValue = node . find ( '[name="' + compared + '"]' ) . val ( ) ; if ( ! comparedValue ) { // {debug} options . debug && window . Debug . log ( { 'node' : node , 'function' : 'validateRule()' , 'arguments' : 'compare: ' + compared + ' rule: ' + rule , 'message' : 'WARNING - Unable to find compared field [name="' + compared + '"]' } ) ; // {/debug} return false ; } if ( ! value || ! eval ( '"' + encodeURIComponent ( value ) + '"' + operator + '"' + encodeURIComponent ( comparedValue ) + '"' ) ) { throw [ options . messages [ operator ] . replace ( ' characters' , '' ) , compared ] ; } } else { // Compare numeric value if ( ! value || isNaN ( value ) || ! eval ( value + operator + parseFloat ( compared ) ) ) { throw [ options . messages [ operator ] . replace ( ' characters' , '' ) , compared ] ; } } break ; } }
Validate an input value against one rule.
If a "value-rule" mismatch occurs, an error is thrown to the caller function.

@param {String} value
@param {*} rule
@param {Boolean} [reversed]

@returns {*} Error if a mismatch occurred.
Validate an input value against one rule . If a value - rule mismatch occurs an error is thrown to the caller function .