springy-framework / brazilian-numbers
PHP class for validate and check brazilian document and numbers
v2.0.0
2024-12-18 20:39 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpmd/phpmd: @stable
- phpstan/phpstan: @stable
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.0
README
This package can validate documents like CPF, CNPJ, CNH, NIS and "inscrição estadual".
It can take the strings with the numbers of documents of people and companies from Brazil and perform format and check digit verifications to determine if they can be valid.
Requirements
- PHP 8.1+
Instalation
To get the latest stable version of this component use:
"require": { "springy-framework/brazilian-numbers": "*" }
in your composer.json file.
Usage
I suppose that the following example is all you need:
<?php require 'vendor/autoload.php'; // If you're using Composer (recommended) // The following numbers can also be used without a mask. $cpf = '899.678.736-12'; $cnpj = '76.871.442/0001-75'; $cnh = '21059294129'; $nis = '640.58791.38-4'; $ierj = '18.251.03-5'; if (Springy\Utils\BrazilianNumbers\Cpf::isValid($cpf)) { echo "CPF valid!\n"; } else { echo "CPF invalid!\n"; } if (Springy\Utils\BrazilianNumbers\Cnpj::isValid($cnpj)) { echo "CNPJ valid!\n"; } else { echo "CNPJ invalid!\n"; } if (Springy\Utils\BrazilianNumbers\Cnh::isValid($cnh)) { echo "CNH valid!\n"; } else { echo "CNH invalid!\n"; } if (Springy\Utils\BrazilianNumbers\Nis::isValid($nis)) { echo "NIS valid!\n"; } else { echo "NIS invalid!\n"; } if (Springy\Utils\BrazilianNumbers\InscricaoEstadual::isValid($ierj)) { echo "IE valid!\n"; } else { echo "IE invalid!\n"; } echo Springy\Utils\BrazilianNumbers\Cpf::mask('89967873612'); echo Springy\Utils\BrazilianNumbers\Cnpj::mask('76871442000175'); echo Springy\Utils\BrazilianNumbers\Nis::mask('64058791384'); echo Springy\Utils\BrazilianNumbers\InscricaoEstadual::mask('18251035'); echo Springy\Utils\BrazilianNumbers\Cpf::unmask($cpf); echo Springy\Utils\BrazilianNumbers\Cnpj::unmask($cnpj); echo Springy\Utils\BrazilianNumbers\Nis::unmask($nis); echo Springy\Utils\BrazilianNumbers\InscricaoEstadual::unmask($ierj);
Contributing
Please read our contributing document and thank you for doing that.
Code of Conduct
In order to ensure that our community is welcoming to all, please review and abide by the code of conduct.
License
This project is licensed under The MIT License (MIT).