Create a new Application.
| Name | Type | Description |
|---|---|---|
options |
Object | The setting options |
Example
var validationEngine = new sogv.Application({
lang: 'en'
});
var form = validationEngine.make({
first_name: 'Leo',
last_lame: 'Lane',
email: 'leo.lane38@example.com',
birthday: '1977-03-07',
creditCard: '4111111111111111',
ip: '8.8.8.8',
locale: 'cy_GB',
country: 'US',
language: 'en_gb',
homepage: 'https://github.com//slaveofgod/sog-validator'
}, {
first_name: 'required|string|length:{"min":2,"max":255}',
last_lame: 'required|string|length:{"min":2,"max":255}',
email: 'required|email',
birthday: 'required|date',
creditCard: 'required|string|card-scheme:{"schemes":["VISA"]}',
ip: 'required|string|ip',
locale: 'required|string|locale',
country: 'required|string|country',
language: 'required|string|language',
homepage: 'required|string|url'
});
if (false === form.isValid()) {
if (false === form.get('name').isValid()) {
form.get('name').errors().first();
}
// ...
}
Members
-
If this parameter is true, it means, that validation called from core.
-
The language used by the application.
Defaults to 'en' (List of ISO 639-1 codes).
Example
// Set the language for the application this.app.lang = 'en';
Methods
-
make (data, rules)sogv.ValidatorHandler
-
Create validators for all the fields
Name Type Description dataObject The data which needs to be validated rulesObject The validation rules Returns:
Type Description sogv.ValidatorHandler -
Create single validator
Name Type Description data* The data which needs to be validated rulesString The validation rules Returns:
Type Description Object Validator object Example
var validationEngine = new sogv.Application({ lang: 'en' }); validator = validationEngine.makeSingle( 'leo.lane38@example.com', 'required|email' ); if (false === validator.isValid()) { validator.errors().first(); }