PHP Classes

PHP Validar CPF e CNPJ: Validate Brazil fiscal numbers

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 202 All time: 8,466 This week: 660Up
Version License PHP version Categories
chave-fiscal 1.0.0GNU General Publi...5.0PHP 5, Finances, Validation
Description 

Author

This package is specific mainly for applications used in Brazil Brazil .

This class can validate Brazil fiscal numbers.

It can take either a CPF or a CNPJ number, clean separator characters and validate it by verifying its length and the check digits.

The class can also return the fiscal number formatted with separator characters.

Picture of Pablo Veinberg
Name: Pablo Veinberg <contact>
Classes: 1 package by
Country: Brazil Brazil

 

Example

<!DOCTYPE html>

<html>
    <head>
        <title>Validador de CPF</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <link href="./css/style.css" rel="stylesheet"/>
    </head>
    <body>
        <div id="content">
           
         
            <h2>Validar CPF</h2>
            <div>
                <form method="POST">
                    <label>
                        Ingresse o CPF (Apenas números):
                    </label>
                    <input type="text" name="cpf" maxlength="11"/>
                    <input type="submit" value="Validar"/>
                </form>
            </div>
            <?php if (!is_null($_POST) && !empty($_POST['cpf'])): ?>
<div>

                    <?php
                    $cpf
= $_POST['cpf'];
                    unset(
$_POST);

                    require_once
'./classes/ValidarChaveFiscal.php';
                   
$validador = new ValidarChaveFiscal($cpf, "cpf");
                    if (
$validador->isValido()) {
                        echo
"<p class='valido'>O CPF {$validador->getChaveFormatada()} é válido.</p>";
                    } else {
                        echo
"<p class='erro'>O CPF {$validador->getChaveFormatada()} não é válido.</p>";
                        foreach (
$validador->getErros() as $erro) {
                            echo
"<li class='erro'>{$erro}</li>";
                        }
                    }
                   
?>
</div>
            <?php endif; ?>
<p><a href="./">Voltar</a></p>
        </div>
    </body>
</html>


  Files folder image Files (6)  
File Role Description
Files folder imageclasses (1 file)
Files folder imagecss (1 file)
Files folder imageincludes (1 file)
Accessible without login Plain text file cnpj.php Example CNPJ Test Example
Accessible without login Plain text file cpf.php Example CPF Test Example
Accessible without login Plain text file index.php Example Index

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:202
This week:0
All time:8,466
This week:660Up