mateusjunges/cpf-cnpj-validator

A simple class to validate CPF and CNPJ numbers

v1.0.0 2022-08-19 13:25 UTC

This package is auto-updated.

Last update: 2024-04-19 17:13:08 UTC


README

art/laravel-kafka.png

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!

Sponsor Me

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.