PHPackages                             jamacio/document-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. jamacio/document-validator

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

jamacio/document-validator
==========================

A PHP library for validating and formatting Brazilian CPF and CNPJ numbers.

v1.0.4(1y ago)099MITPHPPHP &gt;=7.2

Since Apr 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jamacio/document-validator)[ Packagist](https://packagist.org/packages/jamacio/document-validator)[ Docs](https://github.com/jamacio/document-validator)[ RSS](/packages/jamacio-document-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

Document Validator
==================

[](#document-validator)

Document Validator is a PHP library designed for validating and formatting Brazilian CPF and CNPJ numbers. It offers easy-to-use static methods to verify the correctness of these documents using the official algorithms, as well as to apply standard masks for displaying them.

Features
--------

[](#features)

- **CPF Validation:** Validates Brazilian CPF numbers (11 digits) using the official algorithm.
- **CNPJ Validation:** Validates Brazilian CNPJ numbers (14 digits) using the official algorithm.
- **Document Identification:** Automatically determines if the provided number is a CPF or CNPJ based on its digit count.
- **Formatting:** Applies standard masks:
    - **CPF Format:** `XXX.XXX.XXX-XX`
    - **CNPJ Format:** `XX.XXX.XXX/XXXX-XX`

Requirements
------------

[](#requirements)

- PHP 7.2 or higher
- Composer

Installation
------------

[](#installation)

Install Document Validator via Composer by running the following command in your terminal:

```
composer require jamacio/document-validator
```

Usage
-----

[](#usage)

Ensure Composer's autoloader is included in your project.

```
require __DIR__ . '/vendor/autoload.php';
```

> **Note:** If you are using a CMS or framework (e.g., Laravel, Symfony), this step is usually not necessary as the autoloader is already included.

Then, use the DocumentValidator class as follows:

```
