wasim/pk-cnic-validator 问题修复 & 功能扩展

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

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

wasim/pk-cnic-validator

Composer 安装命令:

composer require wasim/pk-cnic-validator

包简介

A PHP package for validating Pakistan CNIC (Computerized National Identity Card) numbers with and without dashes

README 文档

README

A PHP package for validating Pakistan CNIC (Computerized National Identity Card) numbers with and without dashes, following PSR standards.

Features

  • ✅ Validate CNIC numbers with dashes (format: 12345-1234567-1)
  • ✅ Validate CNIC numbers without dashes (format: 1234512345671)
  • ✅ Format CNIC numbers between dash and non-dash formats
  • ✅ Extract detailed information from valid CNIC numbers
  • ✅ Comprehensive validation rules for Pakistan CNIC structure
  • ✅ PSR-12 coding standards compliance
  • ✅ Full unit test coverage
  • ✅ Static analysis with PHPStan

Installation

Via Composer

composer require wasim/pk-cnic-validator

Manual Installation

  1. Clone the repository:
git clone https://github.com/MrWasimAbbasi/pk-cnic-validator.git
cd pk-cnic-validator
  1. Install dependencies:
composer install

Usage

Basic Validation

use PkCnicValidator\CnicValidator;

$validator = new CnicValidator();

// Validate CNIC with dashes
$isValid = $validator->isValid('12345-1234567-1'); // true

// Validate CNIC without dashes
$isValid = $validator->isValid('1234512345671'); // true

// Validate invalid CNIC
$isValid = $validator->isValid('invalid'); // false

Specific Format Validation

// Check if CNIC is in dash format
$hasDashes = $validator->isValidWithDashes('12345-1234567-1'); // true
$hasDashes = $validator->isValidWithDashes('1234512345671'); // false

// Check if CNIC is in numeric format
$isNumeric = $validator->isValidWithoutDashes('1234512345671'); // true
$isNumeric = $validator->isValidWithoutDashes('12345-1234567-1'); // false

Formatting

// Format CNIC to include dashes
$withDashes = $validator->formatWithDashes('1234512345671'); // '12345-1234567-1'

// Format CNIC to remove dashes
$withoutDashes = $validator->formatWithoutDashes('12345-1234567-1'); // '1234512345671'

// Invalid CNIC returns null
$formatted = $validator->formatWithDashes('invalid'); // null

Information Extraction

$info = $validator->extractInfo('12345-1234567-1');

// Returns:
[
    'cnic' => '12345-1234567-1',
    'cnic_with_dashes' => '12345-1234567-1',
    'cnic_without_dashes' => '1234512345671',
    'province_code' => '1',
    'district_code' => '12',
    'family_number' => '345',
    'serial_number' => '1234567',
    'check_digit' => '1'
]

CNIC Structure

Pakistan CNIC follows this structure:

  • Province Code (1 digit): 1-9
  • District Code (2 digits): 11-99
  • Family Number (3 digits): 001-999
  • Serial Number (7 digits): 0000001-9999999
  • Check Digit (1 digit): 0-9

Valid Formats

  1. With Dashes: 12345-1234567-1
  2. Without Dashes: 1234512345671

Testing

Run Tests

# Run all tests
composer test

# Run tests with coverage
composer test-coverage

Code Quality

# Check coding standards
composer cs

# Fix coding standards automatically
composer cs-fix

# Run static analysis
composer stan

Requirements

  • PHP >= 7.4
  • Composer

Development

Project Structure

pk-cnic-validator/
├── src/
│   └── CnicValidator.php
├── tests/
│   ├── CnicValidatorTest.php
│   └── IntegrationTest.php
├── composer.json
├── phpunit.xml
├── phpcs.xml
├── phpstan.neon
└── README.md

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

License

This package is open-sourced software licensed under the MIT license.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Changelog

Version 1.0.0

  • Initial release
  • CNIC validation with and without dashes
  • Format conversion functionality
  • Information extraction
  • Comprehensive test coverage

wasim/pk-cnic-validator 适用场景与选型建议

wasim/pk-cnic-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 wasim/pk-cnic-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wasim/pk-cnic-validator 我们能提供哪些服务?
定制开发 / 二次开发

基于 wasim/pk-cnic-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-29