PHPackages                             fernandorech/br-commons - 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. fernandorech/br-commons

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

fernandorech/br-commons
=======================

Helps creates CPF and CNPJ validations

1.0.3(10mo ago)4109MITPHP

Since Sep 16Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/fernandorech/BrCommons)[ Packagist](https://packagist.org/packages/fernandorech/br-commons)[ RSS](/packages/fernandorech-br-commons/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

BrCommons Validators
====================

[](#brcommons-validators)

[![Total Downloads](https://camo.githubusercontent.com/f65e9b603ef6b6cef8dc8524a1c72d34daec864f2c83510bde8135d897b31323/687474703a2f2f706f7365722e707567782e6f72672f6665726e616e646f726563682f62722d636f6d6d6f6e732f646f776e6c6f616473)](https://packagist.org/packages/fernandorech/br-commons) [![License](https://camo.githubusercontent.com/91c85c05aaae077a724109b023f91b2b006a6dcfd43864f7c73e83925a565790/687474703a2f2f706f7365722e707567782e6f72672f6665726e616e646f726563682f62722d636f6d6d6f6e732f6c6963656e7365)](https://packagist.org/packages/fernandorech/br-commons)

BrCommons validator is a set of useful validators that helps you develop fast and reliable code. Has zero dependencies.

Installation by composer
------------------------

[](#installation-by-composer)

Run `composer require fernandorech/br-commons`.

Updates
-------

[](#updates)

Has the new validation CNPJ Alfanumérico.

BrCommons
---------

[](#brcommons)

It's a class that helps you to validate and format CPF and CNPJ by given a string.

Examples 1: Simple document format
----------------------------------

[](#examples-1-simple-document-format)

```
use BrCommons\BrCommons;
    $document = BrCommons::from('44975583046');
    echo $document->toString(); // will print '449.755.830-46'

```

Example 2: validation of a cpf
------------------------------

[](#example-2-validation-of-a-cpf)

```
    if(BrCommons::isValid('44975583046') {
        // do some code
    } else {
        // other stuff
    }

```

Example 3: throw an exception if a document is not valid
--------------------------------------------------------

[](#example-3-throw-an-exception-if-a-document-is-not-valid)

```
try {
    $document = BrCommons::from('4497558', true); //it will thrown an exception
} catch (DocumentException $e) {
    //do code
}

```

Example 4: Return formatted value without create an object
----------------------------------------------------------

[](#example-4-return-formatted-value-without-create-an-object)

```
echo BrCommons::format('44975583046');

```

Example 5: Use CPF or CNPJ directly
-----------------------------------

[](#example-5-use-cpf-or-cnpj-directly)

```
$cpf = CPF::from('44975583046');
$cnpj  CNPJ::from('14328920000148');

```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance54

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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 ~339 days

Total

4

Last Release

312d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a9658dda99158f61abba9a029adf445f31a531cd0a1c819eb02bd86753d9781?d=identicon)[fernandorech](/maintainers/fernandorech)

---

Top Contributors

[![fernandorech](https://avatars.githubusercontent.com/u/3988581?v=4)](https://github.com/fernandorech "fernandorech (8 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/fernandorech-br-commons/health.svg)

```
[![Health](https://phpackages.com/badges/fernandorech-br-commons/health.svg)](https://phpackages.com/packages/fernandorech-br-commons)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

54013.2M446](/packages/nette-forms)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)

PHPackages © 2026

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