Class: LengthValidator

sogv.LengthValidator

Validates that a given string length is between some minimum and maximum value.

new sogv.LengthValidator (data, options, optionRules, lang, internal)

Create a new Validator.

Name Type Description
data * The data which needs to be validated.
options Object The setting options
optionRules Object The validation rules for setting options.
lang String The language used by the application. Default: "en".
internal Boolean If this parameter is true, it means, that validation called from core.
Properties:
Name Type Description
alias Array

The aliases for the current validator.

They could be used in the short validation format.

Defined aliases: ['length', 'len'].

options Object The description of the required options.
Example
var validator = new sogv.LengthValidator(data, {min: 10});
if (false === validator.isValid()) {
     validator.errors().first();
}

Extends

Members

allowEmptyString Boolean

If set to true, empty strings are considered valid.

The default false value considers empty strings not valid.

Default: false.

data * inherited

Data that needs to be validated.

exactMessage String

The message that will be shown if min and max values are equal and the underlying value's length is not exactly this value.

Default: "This value should have exactly %%limit%% characters.".

You can use the following parameters in this message:

Parameter Description
%%limit%% The exact expected length
%%value%% The current (invalid) value

lang String inherited

Language of error messages.

max Integer

This option is the "max" length value. Validation will fail if the given value's length is greater than this max value. This option is required when the "min: option is not defined.

maxMessage String

The message that will be shown if the underlying value's length is more than the max option.

Default: "This value is too long. It should have %%limit%% characters or less.".

You can use the following parameters in this message:

Parameter Description
%%limit%% The expected maximum length
%%value%% The current (invalid) value

min Integer

This option is the "min" length value. Validation will fail if the given value's length is less than this min value. This option is required when the max option is not defined. It is important to notice that NULL values and empty strings are considered valid no matter if the constraint required a minimum length. Validators are triggered only if the value is not blank.

minMessage String

The message that will be shown if the underlying value's length is less than the min option.

Default: "This value is too short. It should have %%limit%% characters or more.".

You can use the following parameters in this message:

Parameter Description
%%limit%% The expected minimum length
%%value%% The current (invalid) value

normalize Boolean

Normalizer string before validate (trim, etc.).

Default: false

Methods

errors ()sogv.Error inherited

Return error errors

Returns:
Type Description
sogv.Error Error messages

isValid ()Boolean inherited overrides

Check if data valid.

Returns:
Type Description
Boolean Validation status