springy-framework/brazilian-numbers

PHP class for validate and check brazilian document and numbers

v1.0.1 2021-07-22 19:55 UTC

This package is auto-updated.

Last update: 2024-10-23 03:53:40 UTC


README

This package can validate documents like CPF, CNPJ, CNH and NIS.

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.

Latest Stable Version Tests Build Status PHPStan StyleCI Total Downloads License

Requirements

  • PHP 7.3+

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)

$brNum = new Springy\BrazilianNumbers();

// 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';

if ($brNum->isCpfValid($cpf)) {
    echo "CPF valid!\n";
} else {
    echo "CPF invalid!\n";
}

if ($brNum->isCnpjValid($cnpj)) {
    echo "CNPJ valid!\n";
} else {
    echo "CNPJ invalid!\n";
}

if ($brNum->isCnhValid($cnh)) {
    echo "CNH valid!\n";
} else {
    echo "CNH invalid!\n";
}

if ($brNum->isNisValid($nis)) {
    echo "NIS valid!\n";
} else {
    echo "NIS invalid!\n";
}

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).