PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Fernando Val   PHP Brazilian Numbers Validation   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Read me
Class: PHP Brazilian Numbers Validation
Validate documents like CPF, CNPJ, CNH and NIS
Author: By
Last change:
Date: 3 years ago
Size: 2,631 bytes
 

Contents

Class file image Download

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