PHPackages                             laravel-enso/cnp-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. laravel-enso/cnp-validator

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

laravel-enso/cnp-validator
==========================

Romanian CNP validator for Laravel

5.0.3(1w ago)211.6k↓71.8%3MITPHPPHP ^8.1CI failing

Since Mar 21Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/laravel-enso/cnp-validator)[ Packagist](https://packagist.org/packages/laravel-enso/cnp-validator)[ Docs](https://github.com/laravel-enso/CnpValidator)[ RSS](/packages/laravel-enso-cnp-validator/feed)WikiDiscussions master Synced yesterday

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

CNP Validator
=============

[](#cnp-validator)

[![License](https://camo.githubusercontent.com/20d90544c823b8a7f0c11af947d8f7b173f64403716d140c4a76abdbfa6b65e7/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f636e702d76616c696461746f722f6c6963656e7365)](LICENSE)[![Stable](https://camo.githubusercontent.com/15c9b51d06713d06e7268c004e8aad8ef56aa051bdeb47c2d55cfc5c7a189cba/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f636e702d76616c696461746f722f76657273696f6e)](https://packagist.org/packages/laravel-enso/cnp-validator)[![Downloads](https://camo.githubusercontent.com/dfdf3f850e73134f1e9087b9b629ad1d762b322f5ddc0678c7ea90629b0af458/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f636e702d76616c696461746f722f646f776e6c6f616473)](https://packagist.org/packages/laravel-enso/cnp-validator)[![PHP](https://camo.githubusercontent.com/f0a519bab181e5f3b2132f6d5f1ccbe7f653687349e86c5b31f34926405dc5f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312532422d3737376262342e737667)](composer.json)[![Issues](https://camo.githubusercontent.com/7b23dce9c2f382fbf98879bf771f1b5d90ef17310359bb3a6a0d3e5a48c1f0a7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c61726176656c2d656e736f2f636e702d76616c696461746f722e737667)](https://github.com/laravel-enso/cnp-validator/issues)[![Merge Requests](https://camo.githubusercontent.com/04efed314c95595ec8bd04b4c017b05e197f4297f0823ea3e288885b63c9d018/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6c61726176656c2d656e736f2f636e702d76616c696461746f722e737667)](https://github.com/laravel-enso/cnp-validator/pulls)

Description
-----------

[](#description)

CNP Validator provides a dedicated Laravel validation rule for Romanian personal numeric codes.

The package exposes a lightweight validation rule that checks whether a value is numeric, has the expected 13-digit length, contains a valid encoded birth date, and matches the official CNP checksum.

It works independently of the Enso ecosystem and can be used in any Laravel application that relies on Laravel's validator.

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

[](#installation)

Install the package:

```
composer require laravel-enso/cnp-validator
```

No additional service provider registration is required.

Features
--------

[](#features)

- Registers a `cnp` validator rule through Laravel package auto-discovery.
- Provides a Laravel validation rule through `LaravelEnso\CnpValidator\Validators\Cnp`.
- Validates that the CNP contains only numeric digits.
- Validates the required 13-character length.
- Validates the encoded date portion of the CNP.
- Validates the checksum using the official control hash table.
- Exposes a reusable low-level validator helper through `LaravelEnso\CnpValidator\Validators\Validator`.

Usage
-----

[](#usage)

Use the rule in a form request or validator instance:

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

$validator = Validator::make(
    ['cnp' => '1800219081826'],
    ['cnp' => ['nullable', 'cnp']],
);
```

Or use the rule object directly:

```
use Illuminate\Support\Facades\Validator;
use LaravelEnso\CnpValidator\Validators\Cnp;

$validator = Validator::make(
    ['cnp' => '1800219081826'],
    ['cnp' => ['nullable', new Cnp()]],
);
```

Example in a form request:

```
use Illuminate\Validation\Rule;
use LaravelEnso\CnpValidator\Validators\Cnp;

public function rules(): array
{
    return [
        'cnp' => [
            'nullable',
            'max:13',
            new Cnp(),
            Rule::unique('users', 'nin'),
        ],
    ];
}
```

::: warning Note The rule object reports failed validation with the `Invalid` message. The string rule reports failed validation with `The :attribute must be a valid CNP.`.

If you want a localized or more specific validation message, map that message in your validation language files or customize it in the consuming validator layer. :::

API
---

[](#api)

### Validation Rule

[](#validation-rule)

String rule:

- `cnp`

The string rule is registered automatically by the package service provider and reports failed validation with `The :attribute must be a valid CNP.`.

`LaravelEnso\CnpValidator\Validators\Cnp`

Public entry point:

- `validate(string $attribute, mixed $value, Closure $fail): void`

The rule calls the internal validator and fails the field when the provided CNP is invalid.

### Validator Helper

[](#validator-helper)

`LaravelEnso\CnpValidator\Validators\Validator`

Public methods:

- `__construct(?string $cnp = null)`
- `fails(): bool`
- `passes(): bool`

Validation flow:

- numeric-only check
- 13-digit length check
- encoded date validation
- checksum validation

Depends On
----------

[](#depends-on)

Framework dependency:

- [`laravel/framework`](https://github.com/laravel/framework) [↗](https://github.com/laravel/framework)

Contributions
-------------

[](#contributions)

are welcome. Pull requests are great, but issues are good too.

Thank you to all the people who already contributed to Enso!

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance95

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 72% 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 ~64 days

Recently: every ~26 days

Total

54

Last Release

7d ago

Major Versions

1.4.3 → 2.0.02020-06-23

2.1.0 → 3.0.02023-03-21

3.3.0 → 4.0.02026-04-09

4.0.2 → 5.0.02026-07-01

PHP version history (5 changes)1.0.0PHP &gt;=5.6.4

1.3.1PHP &gt;=7.1.0

1.4.0PHP &gt;=7.4.0

2.0.2PHP &gt;=8.0

3.1.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16073274?v=4)[Adrian Ocneanu](/maintainers/aocneanu)[@aocneanu](https://github.com/aocneanu)

---

Top Contributors

[![aocneanu](https://avatars.githubusercontent.com/u/16073274?v=4)](https://github.com/aocneanu "aocneanu (59 commits)")[![vmcvlad](https://avatars.githubusercontent.com/u/37445394?v=4)](https://github.com/vmcvlad "vmcvlad (8 commits)")[![gandesc](https://avatars.githubusercontent.com/u/14071925?v=4)](https://github.com/gandesc "gandesc (7 commits)")[![GITmanuela](https://avatars.githubusercontent.com/u/44998004?v=4)](https://github.com/GITmanuela "GITmanuela (2 commits)")[![DevIonut](https://avatars.githubusercontent.com/u/19207797?v=4)](https://github.com/DevIonut "DevIonut (2 commits)")[![raftx24](https://avatars.githubusercontent.com/u/10864136?v=4)](https://github.com/raftx24 "raftx24 (2 commits)")[![AbdullahiAbdulkabir](https://avatars.githubusercontent.com/u/33360580?v=4)](https://github.com/AbdullahiAbdulkabir "AbdullahiAbdulkabir (1 commits)")[![ottoszika](https://avatars.githubusercontent.com/u/7945963?v=4)](https://github.com/ottoszika "ottoszika (1 commits)")

---

Tags

cnp-validatorlaravellaravel-cnp-validatorlaravel-ensolaravel-validationlaravel-validation-rulesromanian-cnpvalidatorlaravelvalidatorCNPlaravel-ensocnp-validator

### Embed Badge

![Health badge](/badges/laravel-enso-cnp-validator/health.svg)

```
[![Health](https://phpackages.com/badges/laravel-enso-cnp-validator/health.svg)](https://phpackages.com/packages/laravel-enso-cnp-validator)
```

###  Alternatives

[unopim/unopim

UnoPim Laravel PIM

10.8k2.5k](/packages/unopim-unopim)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21327.3k4](/packages/ecotone-laravel)[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1045.1k8](/packages/carsdotcom-laravel-json-schema)

PHPackages © 2026

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