Custom validator rules for Laravel 5.5+.
This package contains custom validator rules for laravel 5.5+, made first for my personal use; so it's grwoing damn slowly 😫! If you don't find anything useful, please tell me or make a PR.
Important: This project was made thinking in package autodiscover, so it needs at least version 5.5+ of Laravel Framework
composer require wemersonrv/laravel-custom-rules
Use it with laravel validator rules in the way you most like: Custom Request, \Validator
facade, etc.
$rules = [
'cpf' => 'required,cpf',
'cnpj' => 'required,cnpj',
'cellphone' => 'mobile_br',
'landline' => 'landline_br',
'postal_code' => 'cep',
'mac' => 'required|mac_address',
];
$errorMsgs = [
'cpf' => 'The :attribute must be a valid Brazilian CPF.',
'cnpj' => 'The :attribute must be a valid Brazilian CNPJ.',
'mobile_br' => 'Invalid mobile number.', // The show is yours, do as you want!
'landline_br' => 'Invalid landline number.',
'cep' => 'The :attribute must be a valid Brazilian ZIP Code (CEP).',
'mac_address' => 'The :attribute must be a valid MAC address',
];
$validator = \Validator::make($request->all(), $rules, $errorMsgs);
if($validator->fails()){
return response($validator->errors(), 400);
}
- Brazilian CPF
- Brazilian CNPJ
- Brazilian Mobile phone with 9 digit
- Brazilian ZIP code (CEP)
- Brazilian Landline phone
- Brazilian states (UF)
- Mac Address
- 0.6.2
- BUGFIX: Fix CNPJ digits check
- CHANGE: Fix digit calculation, force 0 when rest result is 10
- 0.6.1
- BUGFIX: Fix CPF digits check
- CHANGE: Fix digit calculation, force 0 when rest result is 10
- 0.6.0
- Macc Address
- ADD: Mac Address rule (
mac_address
)
- 0.5.0
- Brazilian Landline number
- ADD: Brazilian Landline rule (
landline_br
)
- 0.4.0
- Brazilian ZIP Code (CEP)
- ADD: Brazilian Postal Code (
cep
)
- 0.3.1
- Sanitize value before validation
- CHANGE: Extract only digits (without mask chars) to validate
- 0.3.0
- Brazilian CNPJ
- ADD: Brazilian CNPJ rule (
cnpj
)
- 0.2.0
- Brazilian Mobile (with 9 digit check)
- ADD: Brazilian Mobile rule (
mobile_br
)
- 0.1.1
- BUGFIX: Just Service provider requires, bu changing namespace
- CHANGE: From
use Rules\Cpf
touse Wemersonrv\CustomRules\Rules\Cpf
- 0.1.0
- The first proper release
- ADD: Brazilian CPF rule (
cpf
)
- 0.0.1
- Work in progress
- Laravel Framework
Wemerson Guimarães – @WemersonCG – [email protected]
Distributed under the GPLv3 license. See LICENSE.md for more information.