PHPackages                             modulae/ptbr-doc-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. modulae/ptbr-doc-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

modulae/ptbr-doc-validator
==========================

Brazilian document validators for Laravel.

0.1.1(2mo ago)0152↓50%[1 PRs](https://github.com/modulae/ptbr-doc-validator/pulls)MITPHPPHP ^8.3CI passing

Since Feb 19Pushed 2mo agoCompare

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

READMEChangelogDependencies (11)Versions (4)Used By (0)

Brazilian document validators for Laravel.
==========================================

[](#brazilian-document-validators-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3f9ca03fa718b26afd47f8b6fd79d381bc4d872a41c9b746c2bc60136b4fe3f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f64756c61652f707462722d646f632d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/modulae/ptbr-doc-validator)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ae34ddd5091038e856b301e0917765af50bcdab6292fedec694503fc9246f3cd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f64756c61652f707462722d646f632d76616c696461746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/modulae/ptbr-doc-validator/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/00f1f467cb2a3f6f5594d4d9d494d8d55201a7757f6ba4baeb489c4beff9ef0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f64756c61652f707462722d646f632d76616c696461746f722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/modulae/ptbr-doc-validator/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a29312baa5de0a4b2a565afc463b09a25521739029417cd44aa54df82c1e64b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f64756c61652f707462722d646f632d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/modulae/ptbr-doc-validator)

A lightweight Laravel package that provides validators and utilities for common Brazilian documents. The first supported document is CNPJ, including support for alphanumeric variants that are to be introduced in June 2026. It includes:

- A `cnpj` validation rule registered with Laravel's `Validator` facade.
- A `Cnpj` value object with helpers to normalize, format, cast in Eloquent models, and validate values.
- A `cnpjToString` helper to normalize strings and arrays of CNPJ values.
- Localized validation error messages (EN and PT-BR).

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

[](#installation)

Install via Composer:

```
composer require modulae/ptbr-doc-validator
```

Publish translations (optional, if you want to customize messages):

```
php artisan vendor:publish --tag="ptbr-doc-validator-translations"
```

Usage
-----

[](#usage)

### 1) Using the built-in `cnpj` validation rule

[](#1-using-the-built-in-cnpj-validation-rule)

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make(
    ['cnpj' => 'T6.JSP.XPS/0001-11'],
    ['cnpj' => 'cnpj']
);

$validator->passes(); // true/false
```

### 2) Using the `Cnpj` value object

[](#2-using-the-cnpj-value-object)

```
use Modulae\PTBRDocValidator\ValueObjects\Cnpj;

$cnpj = new Cnpj('T6.JSP.XPS/0001-11');
$cnpj->isValid();     // bool
$cnpj->raw();         // "T6JSPXPS000111"
$cnpj->formatted();   // "T6.JSP.XPS/0001-11"
(string) $cnpj;       // "T6JSPXPS000111"
```

Eloquent cast example:

```
class Company extends Model
{
    protected $casts = [
        'cnpj' => \Modulae\PTBRDocValidator\ValueObjects\Cnpj::class,
    ];
}
```

### 3) Using the `cnpjToString` helper

[](#3-using-the-cnpjtostring-helper)

```
use function Modulae\PTBRDocValidator\cnpjToString;

cnpjToString('T6.JSP.XPS/0001-11');
// => "T6JSPXPS000111"

cnpjToString(['32.332.643/0001-29', 'T6.JSP.XPS/0001-11']);
// => ['32332643000129', 'T6JSPXPS000111']
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance86

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

88d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1358552?v=4)[João Prado](/maintainers/joaoprado)[@joaoprado](https://github.com/joaoprado)

---

Top Contributors

[![joaoprado](https://avatars.githubusercontent.com/u/1358552?v=4)](https://github.com/joaoprado "joaoprado (3 commits)")

---

Tags

laravelModulaeptbr-doc-validator

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/modulae-ptbr-doc-validator/health.svg)

```
[![Health](https://phpackages.com/badges/modulae-ptbr-doc-validator/health.svg)](https://phpackages.com/packages/modulae-ptbr-doc-validator)
```

###  Alternatives

[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[ziming/laravel-zxcvbn

Zxcvbn Password validation rule for Laravel

3056.7k](/packages/ziming-laravel-zxcvbn)[laravel-validation-rules/phone

Validate that a phone number is in the correct format

69355.5k](/packages/laravel-validation-rules-phone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
