This validator checks if the given field`s values length is lesss than or equal `length`.
@class Definition
@method validatesLengthOf
@param {string} field - The field to validate
@param {integer} length - The maximum length

@return {Definition}
359316
function(field, length) {
    if (Array.isArray(field)) {
      return this.validateFieldsHelper(field, [length], this.validatesLengthOf)
    }

    return this.validates(field, function() {
      var valid = true
      if (this[field]) valid = this[field].length <= length
      if (!valid)
        this.errors.add(field, 'maximum length of ' + length + ' exceeded')
      return valid
    })
  }
35840
function splitField(chunk, strict) {
  const field = String(chunk);
  const index = field.indexOf(':');

  if (index === -1) {
    throw new SyntaxError(`field separator is not found: "${field}"`);
  }

  const label = field.slice(0, index);
  const value = field.slice(index + 1);

  if (strict && !(0, _validator.isValidLabel)(label)) {
    throw new SyntaxError(`unexpected character of label: "${label}"`);
  }

  if (strict && !(0, _validator.isValidValue)(value)) {
    throw new SyntaxError(`unexpected character of value: "${value}"`);
  }

  return {
    label,
    value
  };
}
51731
function truncate (value, length) {
  length = length || 15
  if( !value || typeof value !== 'string' ) return ''
  if( value.length <= length) return value
  return value.substring(0, length) + '...'
}
886709
def _validate_maxlength(self, max_length, field, value):
        
        if isinstance(value, Iterable) and len(value) > max_length:
            self._error(field, errors.MAX_LENGTH, len(value))
919024
function validationPlugin(Schema) {
    var constructor = Schema.prototype.constructor;

    Schema.prototype.constructor = function (name, schema) {
        var key;
        var fieldDefinition;

        if (arguments.length === 1) {
            schema = arguments[0];
        }

        // call super constructor
        constructor.apply(this, arguments);

        this.validators = {};

        for (key in schema) {
            if (schema.hasOwnProperty(key)) {
                fieldDefinition = schema[key];
                this.validators[key] = [];

                // predefined validators
                if (fieldDefinition.required) {
                    this.validators[key].push(defaultValidators.required());
                }
                if (value(fieldDefinition.enum).typeOf(Array)) {
                    this.validators[key].push(defaultValidators.enum(fieldDefinition.enum));
                }

                if (value(fieldDefinition.min).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.min(fieldDefinition.min));
                }

                if (value(fieldDefinition.max).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.max(fieldDefinition.max));
                }

                if (value(fieldDefinition.minLength).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.minLength(fieldDefinition.minLength));
                }

                if (value(fieldDefinition.maxLength).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.maxLength(fieldDefinition.maxLength));
                }

                if (value(fieldDefinition.hasLength).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.hasLength(fieldDefinition.hasLength));
                }

                // The matches validators works on all types, so we just check if the key is present
                if ("matches" in fieldDefinition) {
                    this.validators[key].push(defaultValidators.matches(fieldDefinition.matches));
                }

                // custom validators
                if (value(fieldDefinition.validate).typeOf(Function)) {
                    this.validators[key].push(fieldDefinition.validate);
                } else if (value(fieldDefinition.validate).typeOf(Array)) {
                    this.validators[key] = this.validators[key].concat(fieldDefinition.validate);
                }
            }
        }
    };

    /**
     * Validate if given model matches schema definition. Returns a promise with the validation result object
     * which contains the intermediate result of all synchronous validators.
     *
     * @param {Object} model
     * @param {Function=} callback
     * @returns {Promise}
     */
    Schema.prototype.validate = function (model, callback) {
        var self = this;
        var pending = 0;
        var result = {
            model: model,
            result: true,
            errors: {}
        };
        var promise;

        function handleFieldErrors(key, fieldErrors) {
            if (fieldErrors.length > 0) {
                result.result = false;
                result.errors[key] = fieldErrors;
            }
        }

        function doCallback() {
            callback(result);
        }

        if (value(model).notTypeOf(Object)) {
            throw new TypeError("Model must be an object");
        }

        if (!this.validators) {
            throw new Error("Validators not defined: Have you registered the validate plugin before any schema definitions?");
        }

        promise = new Promise(function (resolve) {
            function done() {
                if (typeof callback === "function") {
                    setTimeout(doCallback, 0);
                }
                resolve(result);
            }

            if (self.fields.length === 0) {
                done();
                return;
            }

            pending = self.fields.length;

            self.fields.forEach(function (key) {
                var fieldErrors = runValidation(self.validators[key], model[key], model, function onFieldValidation(fieldErrors) {
                    pending--;
                    handleFieldErrors(key, fieldErrors);

                    if (pending === 0) {
                        done();
                    }
                });

                handleFieldErrors(key, fieldErrors);
            });
        });
        // Attach intermediate result to promise
        promise.validation = result;

        return promise;
    };
}
932149
function checkLength(size, schema, key) {
    //Check if it is an int
    if (Number.isInteger(schema[SCHEMALENGTH])) {
      if (size != schema[SCHEMALENGTH]) {
        throw new ValidationException("Size of " + key + " is not correct.");
      }
    } else if (typeof schema[SCHEMALENGTH] == "string") {
      if (
        size < getMin(schema[SCHEMALENGTH], key) ||
        size > getMax(schema[SCHEMALENGTH], key)
      ) {
        throw new ValidationException("Size of " + key + " is not correct.");
      }
    } else {
      throw new ValidationException(SCHEMALENGTH + " cast exception: " + key);
    }
  }
628498
function validateLength(attr, conf, err) {
    if (nullCheck.call(this, attr, conf, err)) return;

    var len = this[attr].length;
    if (conf.min && len < conf.min) {
        err('min');
    }
    if (conf.max && len > conf.max) {
        err('max');
    }
    if (conf.is && len !== conf.is) {
        err('is');
    }
}
1192886
function getLengthOfLength(lenValue, indefiniteLength) {
  var lenOfLen;
  
  if (indefiniteLength) {
    lenOfLen = 3;
  } else if (lenValue > 0x00FFFFFF) {
    lenOfLen = 5;
  } else if (lenValue > 0x0000FFFF) {
    lenOfLen = 4;
  } else if (lenValue > 0x000000FF) {
    lenOfLen = 3;
  } else if (lenValue > 0x0000007F) {
    lenOfLen = 2; 
  } else {
    lenOfLen = 1;
  }
  
  return lenOfLen
}
747588
function (field) {
      var ctr = this.constructor;
      var names = ctr.__names__;
      var constraints = ctr.__constraints__;
      if (typeof field === 'number') {
        if (field < 0 || field > names.length - 1) {
          throw new Error('Field index out of range: ' + field);
        }
        field = names[field];
      } else {
        if (!constraints.hasOwnProperty(field)) {
          throw new Error('Field name does not exist: ' + field);
        }
      }
      return this[field];
    }
1334254
function validateField(field, cb) {
        if (_.isArray(field.validation)) {
            async.each(field.validation, performValidation(field), function(err) {
                cb(err);
            });
        } else {
            cb();
        }
    }
896801
function rules () {
        var pub = {};
        pub.maxLength = function (val, max) {

            if (!Array.isArray(val) && typeof val !== 'string' || typeof max !== 'number') {
                return getResult(new Error('rules.maxLength(fail): value must be a string or array, max must be a number'));
            }

            if (val.length > max) {
                return getResult(getError('maxLength', max, val));
            }

            return getResult(null);
        };
        pub.minLength = function (val, min) {

            if (!Array.isArray(val) && typeof val !== 'string' || typeof min !== 'number') {
                return getResult(new Error('rules.minLength(fail): value must be a string or array, min must be a number'));
            }

            if (val.length < min) {
                return getResult(getError('minLength', min, val));
            }

            return getResult(null);
        };
        pub.minimum = function (val, min) {

            if (typeof val !== 'number' || typeof min !== 'number') {
                return getResult(new Error('rules.minimum(fail): value must be a number, min must be a number'));
            }

            if (val < min) {
                return getResult(getError('minimum', min, val));
            }

            return getResult(null);
        };
        pub.maximum = function (val, max) {

            if (typeof val !== 'number' || typeof max !== 'number') {
                return getResult(new Error('rules.maximum(fail): value must be a number, max must be a number'));
            }

            if (val > max) {
                return getResult(getError('maximum', max, val));
            }

            return getResult(null);
        };
        pub.exclusiveMinimum = function (val, min) {

            if (typeof val !== 'number' || typeof min !== 'number') {
                return getResult(new Error('rules.exclusiveMinimum(fail): value must be a number, min must be a number'));
            }

            if (val <= min) {
                return getResult(getError('exclusiveMinimum', min, val));
            }

            return getResult(null);
        };
        pub.exclusiveMaximum = function (val, max) {

            if (typeof val !== 'number' || typeof max !== 'number') {
                return getResult(new Error('rules.exclusiveMaximum(fail): value must be a number, max must be a number'));
            }

            if (val >= max) {
                return getResult(getError('exclusiveMinimum', max, val));
            }

            return getResult(null);
        };
        pub.divisibleBy = function (val, div) {

            if (typeof val !== 'number' || typeof div !== 'number') {
                return getResult(new Error('rules.divisibleBy(fail): value must be a number, div must be a number'));
            }

            var multiplier = Math.max((val - Math.floor(val)).toString().length - 2,
                (div - Math.floor(div)).toString().length - 2);
            multiplier = multiplier > 0 ? Math.pow(10, multiplier) : 1;

            if ((val * multiplier) % (div * multiplier) !== 0) {
                return getResult(getError('divisibleBy', div, val));
            }

            return getResult(null);
        };
        pub.minItems = function (val, min) {

            if (!Array.isArray(val) || typeof min !== 'number') {
                return getResult(new Error('rules.minItems(fail): value must be a array, min must be a number'));
            }

            if (val.length < min) {
                return getResult(getError('minItems', min, val.length));
            }

            return getResult(null);
        };
        pub.maxItems = function (val, max) {

            if (!Array.isArray(val) || typeof max !== 'number') {
                return getResult(new Error('rules.maxItems(fail): value must be a array, max must be a number'));
            }

            if (val.length > max) {
                return getResult(getError('maxItems', max, val.length));
            }

            return getResult(null);
        };
        pub.uniqueItems = function (val) {

            if (!Array.isArray(val)) {
                return getResult(new Error('rules.uniqueItems(fail): value must be a array'));
            }

            if (!(uniqueArrayHelper(val))) {
                return getResult(getError('uniqueItems', val, true));
            }

            return getResult(null);
        };
        pub['enum'] = function (val, en) {

            if (typeof val === 'undefined' || !Array.isArray(en)) {
                return getResult(new Error('rules.enum(fail): value must be a defined and enum mus be a array'));
            }

            if (en.indexOf(val) === -1) {
                return getResult(getError('enum', en, val));
            }

            return getResult(null);
        };

        return pub;
    }
323320
def validate_field(field, params)
      begin
        value = params.fetch(field)
        required_error(field) if value.nil? || value.empty?
      rescue KeyError
        required_error(field)
      end
    end
876286
function STRING(length) {
    length = length || 255;
    if (!(this instanceof STRING)) {
        return new STRING(length);
    }
    this.length = length;
    this.sql = 'VARCHAR(' + length + ')';
}
404949
function isIndex(value, length) {
  var type = typeof value;
  length = length == null ? MAX_SAFE_INTEGER$1 : length;

  return !!length &&
    (type == 'number' ||
      (type != 'symbol' && reIsUint.test(value))) &&
        (value > -1 && value % 1 == 0 && value < length);
}
113809
function ensureLength (self, _newLength) {
  var newLength;
  if (_newLength > MAX_LENGTH) {
    newLength = MAX_LENGTH;
  } else {
    newLength = _newLength | 0;
  }
  var proto = Object.getPrototypeOf(self);
  var cur = proto[length] | 0;
  var num = newLength - cur;
  if (num > 0) {
    var desc = {};
    debug('creating a descriptor object with %o entries', num);
    for (var i = cur; i < newLength; i++) {
      desc[i] = setup(i);
    }
    debug('calling `Object.defineProperties()` with %o entries', num);
    Object.defineProperties(proto, desc);
    proto[length] = newLength;
  }
  return newLength;
}
542858
function matchLength(text, exp) {
  const match = text.match(exp);
  return match ? match[0].length : 0;
}
487299
function (fieldDefinition, fieldName) {
		const severity = propertyHelper.getSeverity(fieldDefinition, undefined, 'mandatory');
		const isMandatoy = propertyHelper.getProperty(fieldDefinition, undefined, 'mandatory');

		// const severity = fieldDefinition.severity;
		// const isMandatoy = fieldDefinition.mandatory;

		if (isMandatoy === true) {
			/**
			 * Just check if for mandatory fields the value is given
			 * @param content the content hash to be validated.
			 */
			return function (content) {
				// get the value from the content hash
				const valueToCheck = content[fieldName];

				// If the value is defined, we need to check it
				if (valueToCheck === undefined || valueToCheck === null) {
					return {
						errorCode: 'MANDATORY_VALUE_MISSING',
						severity: severity,
						fieldName: fieldName
					};
				}
			};

		}
	}