Download the PHP package laravel-enso/cnp-validator without Composer
On this page you can find all versions of the php package laravel-enso/cnp-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laravel-enso/cnp-validator
More information about laravel-enso/cnp-validator
Files in laravel-enso/cnp-validator
Package cnp-validator
Short Description Romanian CNP validator for Laravel
License MIT
Homepage https://github.com/laravel-enso/CnpValidator
Informations about the package cnp-validator
CNP Validator
Description
CNP Validator provides a dedicated Laravel validation rule for Romanian personal numeric codes.
The package exposes a lightweight invokable 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
Install the package:
No additional service provider registration is required.
Features
- Provides an invokable 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
Use the rule in a form request or validator instance:
Example in a form request:
::: warning Note
The package reports failed validation with the Invalid message.
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
Validation Rule
LaravelEnso\CnpValidator\Validators\Cnp
Public entry point:
__invoke($attribute, $value, $fail)
The rule calls the internal validator and fails the field when the provided CNP is invalid.
Validator Helper
LaravelEnso\CnpValidator\Validators\Validator
Public methods:
__construct(?string $cnp = null)fails(string $cnp): boolpasses(): bool
Validation flow:
- numeric-only check
- 13-digit length check
- encoded date validation
- checksum validation
Depends On
Framework dependency:
Contributions
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!