laravel-enso/cnp-validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravel-enso/cnp-validator

Composer 安装命令:

composer require laravel-enso/cnp-validator

包简介

Romanian CNP validator for Laravel

README 文档

README

License Stable Downloads PHP Issues Merge Requests

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:

composer require laravel-enso/cnp-validator

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:

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 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): bool
  • passes(): 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!

统计信息

  • 总下载量: 11.48k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固