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: [' |
options |
Object | The description of the required options. |
Example
var validator = new sogv.CountValidator(data, {"min": 10, "max": 20});
if (false === validator.isValid()) {
validator.errors().first();
}
Extends
Members
-
data * inherited
-
Data that needs to be validated.
-
The message that will be shown if min and max values are equal and the underlying collection elements count is not exactly this value.
Default: "
This collection should contain exactly %%limit%% elements."You can use the following parameters in this message:
Parameter Description %%count%%The current collection size %%limit%%The exact expected collection size -
lang String inherited
-
Language of error messages.
-
This option is the "
max" count value. Validation will fail if the given collection elements count is greater than this max value.This option is required when the min option is not defined.
-
The message that will be shown if the underlying collection elements count is more than the max option.
Default: "
This collection should contain %%limit%% elements or less."You can use the following parameters in this message:
Parameter Description %%count%%The current collection size %%limit%%The upper limit -
This option is the "
min" count value. Validation will fail if the given collection elements count is less than this min value.This option is required when the max option is not defined.
-
The message that will be shown if the underlying collection elements count is less than the min option.
Default: "
This collection should contain %%limit%% elements or more."You can use the following parameters in this message:
Parameter Description %%count%%The current collection size %%limit%%The lower limit
Methods
-
errors ()sogv.Error inherited
-
Return error errors
Returns:
Type Description sogv.Error Error messages -
Check if data valid.
Returns:
Type Description Boolean Validation status