-
-
Notifications
You must be signed in to change notification settings - Fork 175
Controller validation
Class and rule syntax are the same that Laravel Validation class implements.
$validator = JsValidator::make(
[
'name' => 'required',
'password' => 'required|min:8',
'email' => 'required|email|unique:users'
],
[
'name' => 'validation.my_custom_lang_message',
'password.required' => ':attribute can\'t be empty',
'password.min' => ':attribute should has at least :min chars',
],
[
'name' => 'Username',
'password' => 'Password'
'email' => 'E-Mail'
],
'#myform'
);
First argument passed to the make
method is the validation rules that should be applied to the data. The rule syntax is the same that
Laravel Validation
class.
Second (optional) argument passed to the make
method is the custom error messages showed when validation fails.
By default jsValidator
uses the Laravel messages translated according [Laravel Localization][] settings but if you want
you can customize the message for each rule.
**Third (optional) argument** passed to the
make` method is the custom attribute name displayed in error messages.
**Fourth (optional) argument** passed to the
makemethod is the JQuery selector to find the form to validate. By default this selector is
formso, any form will be validated. You can change the default selector in
config/jsvalidation.php` config file