Laravel 5+ Custom Validators
Installation
composer require "tartan/laravel-custom-validator"
Tartan Custom Validators
Add the required validator(s) to boot method of app/Providers/AppServiceProvider.php
, (*1)
Validator::extend('strength', 'Tartan\Validators\CustomValidator@validateStrength');
Validator::extend('iran_billing_id', 'Tartan\Validators\CustomValidator@validateIranBillingId');
Validator::extend('iran_shetab_card', 'Tartan\Validators\CustomValidator@validateShetabCard');
Validator::extend('uuid', 'Tartan\Validators\CustomValidator@validateUuid');
Validator::extend('iran_national_id', 'Tartan\Validators\CustomValidator@validateNationalId');
Add following lines to resources/lang/en/validation.php
in Custom Validation Language Lines
part, (*2)
'strength' => 'The password :attribute is too weak and must contain one or more uppercase, lowercase, numeric, and special character (!@#$%^&*).',
'iran_billing_id' => 'The billing Id `:attribute` is not a valid Billing Id.',
'shetab_card' => 'The card number `:attribute` is not a valid Shetab card number.',
'uuid' => 'The UUID `:attribute` is not a valid UUID.',
'iran_national_id' => 'The national id `:attribute` is not a valid Iran nationa Id.',
Use like other validator, (*3)
...
'national_id' => 'required|iran_national_id|unique:users,national_id',
'password' => 'required|string|strength|min:6'
...
Team
This component is developed by the following person(s) and a bunch of awesome contributors., (*4)
Support This Project
, (*5)
License
The Laravel Custom Validator is open-sourced software licensed under the MIT license, (*6)