PHP Brazilian Numbers Validation: Validate documents like CPF, CNPJ, CNH and NIS

Recommend this page to a friend!
  Info   View files Documentation   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-12-10 (6 months ago) RSS 2.0 feedNot enough user ratingsTotal: 20 All time: 10,276 This week: 291Up
Version License PHP version Categories
brazilian-numbers 1.0.0MIT/X Consortium ...5PHP 5, Validation
Description Author
This package is specific mainly for applications used in Brazil Brazil .

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.

In Portuguese:

Esta classe pode validar documentos como CPF, CNPJ, CNH e NIS.

A class pode pegar strings de texto com os números de documentos de pessoas e empresas do Brasil e realizar validações de formato e dígitos de verificação para determinar se eles podem ser válidos.

Picture of Fernando Val
  Performance   Level  
Name: Fernando Val <contact>
Classes: 5 packages by
Country: Brazil Brazil
Age: 52
All time rank: 2366162 in Brazil Brazil
Week rank: 539 Up33 in Brazil Brazil Up

 

Details

Springy BrazilianNumbers

Brazilian documents numbers validator for PHP.

Latest Stable Version Build Status PHP Composer PHPStan Codacy Badge 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).

  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 file)
Files folder imagetests (5 files)
Accessible without login Plain text file .remarkrc Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file codesize.xml Data Auxiliary data
Accessible without login Plain text file CODE_OF_CONDUCT.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file BrazilianNumbers.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file CnhTest.php Class Class source
  Plain text file CnpjTest.php Class Class source
  Plain text file CpfTest.php Class Class source
  Plain text file NisTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:20
This week:0
All time:10,276
This week:291Up

For more information send a message to info at phpclasses dot org.