utils/validation.js
function generateValidationFn(schema) {
        return function (req) {

            // if already an error, return without doing any additional validation
            if (req.error) { return req; }

            var keys = Object.keys(schema);
            var len = (req.value && req.value.trim().length) || 0;
            var i, key, originalKey;

            for (i = 0; i < keys.length; i++) {
                key = originalKey = keys[i];
                if (key.indexOf('ui-') === 0) {
                    key = key.substring(3);
                }

                // if validation function exists but it returns false then we have error
                if (check[key] && !check[key](schema, req.value)) {
                    var errMsg = schema[key + 'Desc'] || errorMessage[key] || 'Invalid input';
                    req.error = errMsg
                        .replace('{' + key + '}', schema[originalKey])
                        .replace('{value}', req.value)
                        .replace('{length}', len);
                    break;
                }
            }

            return req;
        };
    }
function generateValidationFn(schema) {
        return function (req) {

            // if already an error, return without doing any additional validation
            if (req.error) { return req; }

            var keys = Object.keys(schema);
            var len = (req.value && req.value.trim().length) || 0;
            var i, key, originalKey;

            for (i = 0; i < keys.length; i++) {
                key = originalKey = keys[i];
                if (key.indexOf('ui-') === 0) {
                    key = key.substring(3);
                }

                // if validation function exists but it returns false then we have error
                if (check[key] && !check[key](schema, req.value)) {
                    var errMsg = schema[key + 'Desc'] || errorMessage[key] || 'Invalid input';
                    req.error = errMsg
                        .replace('{' + key + '}', schema[originalKey])
                        .replace('{value}', req.value)
                        .replace('{length}', len);
                    break;
                }
            }

            return req;
        };
    }
function generateValidationFn ( schema ) { return function ( req ) { // if already an error, return without doing any additional validation if ( req . error ) { return req ; } var keys = Object . keys ( schema ) ; var len = ( req . value && req . value . trim ( ) . length ) || 0 ; var i , key , originalKey ; for ( i = 0 ; i < keys . length ; i ++ ) { key = originalKey = keys [ i ] ; if ( key . indexOf ( 'ui-' ) === 0 ) { key = key . substring ( 3 ) ; } // if validation function exists but it returns false then we have error if ( check [ key ] && ! check [ key ] ( schema , req . value ) ) { var errMsg = schema [ key + 'Desc' ] || errorMessage [ key ] || 'Invalid input' ; req . error = errMsg . replace ( '{' + key + '}' , schema [ originalKey ] ) . replace ( '{value}' , req . value ) . replace ( '{length}' , len ) ; break ; } } return req ; } ; }
Generate validator function off of the given schema object
@param schema
@returns {Function}
Generate validator function off of the given schema object