mateusjunges / cpf-cnpj-validator
A simple class to validate CPF and CNPJ numbers
v1.0.0
2022-08-19 13:25 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.25
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.10
- orchestra/testbench: ^7.6
- phpunit/phpunit: ^9.5
README
This package provide a simple API to validate brazilian CPF and CNPJ document numbers.
Sponsor my work!
If you think this package helped you in any way, you can sponsor me on GitHub!
Installation
You can install this package using composer:
composer require mateusjunges/cpf-cnpj-validator
Usage
To validate a document number, you can invoke the Validator
class passing the number
and optionally the document type
as parameters:
use Junges\CpfCnpjValidator\Validator; $v = (new Validator)("360.928.960-01"); // True $v = (new Validator)("360.928.960-01", \Junges\CpfCnpjValidator\Enums\TaxId::CPF); // True $v = (new Validator)("360.928.960-01", \Junges\CpfCnpjValidator\Enums\TaxId::CNPJ); // False $v = (new Validator)("91.881.588/0001-95"); // True $v = (new Validator)("91.881.588/0001-95", \Junges\CpfCnpjValidator\Enums\TaxId::CNPJ); // True $v = (new Validator)("91.881.588/0001-95", \Junges\CpfCnpjValidator\Enums\TaxId::CPF); // True
Testing
Run composer test
to test this package.
Credits
License
This package is open-sourced software licensed under the MIT License. Please see the License file for more information.