gbielbarbosa/stdnum-php
Composer 安装命令:
composer require gbielbarbosa/stdnum-php
包简介
A PHP library to parse, validate and format standard numbers and identifiers.
README 文档
README
stdnum-php is a modern, framework-agnostic PHP 8.1+ library designed for parsing, formatting, and validating standard numbers and alphanumeric identifiers.
This project is an architectural port inspired by the robust python-stdnum library, featuring an object-oriented and extensible design structure natively built for the PHP ecosystem.
Features
- Extensive Coverage: Supports 106 international identification formats spanning across 71 countries.
- Fluent & Static Resolution: Simple dot-notation to dynamically map specific validators (e.g.
br.cpf,us.ssn,cn.uscc). - Laravel Integration Ready: Includes a native generic rule
StdNumRulethat tightly integrates into Laravel's FormRequests and validators. - Standardized Interfaces: All validators rigorously adhere to a single
DocumentInterfacecontract implementingvalidate(),isValid(),format(), andcompact().
Installation
You can install the package via composer:
composer require gbielbarbosa/stdnum-php
Basic Usage
The library acts through a central StdNum factory or you can instance the classes independently.
Pure PHP
You can quickly evaluate identifiers using the dot notation format [iso-code].[identifier-type].
use StdNum\StdNum; // Returns boolean indicating if the identifier is valid $isValid = StdNum::isValid('br.cpf', '390.533.447-05'); // true // Returns a rich ValidationResult Object $result = StdNum::validate('ch.uid', 'CHE-100.155.213'); if (! $result->isValid) { echo $result->error; // "Invalid checksum for Swiss UID" }
Laravel Usage
The package comes bundled with StdNumRule for seamless Laravel integration:
use StdNum\Laravel\Rules\StdNumRule; use Illuminate\Http\Request; public function store(Request $request) { $request->validate([ 'cuit' => ['required', new StdNumRule('ar.cuit')], 'nif' => ['required', new StdNumRule('es.nif')], ]); }
Formatting Identifiers
In addition to checks, each format provides natively tailored presentation routines:
$validator = StdNum::make('cl.rut'); echo $validator->format('125319092'); // Outputs: "12.531.909-2" echo $validator->compact('12.531.909-2'); // Outputs: "125319092"
Supported Formats
Currently supported and rigorously tested identifier types include:
- 🇦🇩 Andorra: NRT
- 🇦🇱 Albania: NIPT
- 🇦🇷 Argentina: CUIT, DNI, CBU
- 🇦🇹 Austria: UID, TIN
- 🇦🇺 Australia: ABN, ACN, TFN
- 🇦🇿 Azerbaijan: VOEN
- 🇧🇪 Belgium: NN, VAT
- 🇧🇬 Bulgaria: EGN, PNF, VAT
- 🇧🇾 Belarus: UNP
- 🇧🇷 Brazil: CPF, CNPJ
- 🇨🇦 Canada: SIN, BN
- 🇨🇭 Switzerland: SSN, UID, VAT
- 🇨🇱 Chile: RUT
- 🇨🇳 China: RIC, USCC
- 🇨🇴 Colombia: NIT
- 🇨🇷 Costa Rica: CPF, CPJ, CR
- 🇨🇺 Cuba: NI
- 🇨🇾 Cyprus: VAT
- 🇨🇿 Czech Republic: DIC, RC
- 🇩🇪 Germany: STNR, VAT
- 🇩🇰 Denmark: CPR, CVR
- 🇩🇴 Dominican Republic: CEDULA, RNC
- 🇪🇨 Ecuador: CI, RUC
- 🇪🇪 Estonia: IK, KMKR, REGISTRIKOOD
- 🇪🇸 Spain: CIF, DNI, NIE, NIF
- 🇫🇮 Finland: ALV, HETU, YTUNNUS
- 🇫🇷 France: SIREN, SIRET, TVA
- 🇬🇧 United Kingdom: NINO, UTR, VAT
- 🇬🇷 Greece: AMKA, VAT
- 🇬🇹 Guatemala: NIT
- 🇮🇩 Indonesia: NIK, NPWP
- 🇮🇪 Ireland: PPS, VAT
- 🇮🇱 Israel: HP, IDNR
- 🇮🇳 India: AADHAAR, EPIC, PAN
- 🇮🇸 Iceland: KENNITALA, VSK
- 🇮🇹 Italy: CodiceFiscale, IVA
- 🇯🇵 Japan: CN
- 🇰🇷 South Korea: BRN, RRN
- 🇱🇹 Lithuania: ASMENS, PVM
- 🇱🇺 Luxembourg: TVA
- 🇱🇻 Latvia: PVN
- 🇲🇨 Monaco: TVA
- 🇲🇩 Moldova: IDNO
- 🇲🇪 Montenegro: PIB
- 🇲🇰 North Macedonia: EDB
- 🇲🇹 Malta: VAT
- 🇲🇺 Mauritius: NID
- 🇲🇽 Mexico: CURP, RFC
- 🇲🇾 Malaysia: NRIC
- 🇳🇱 Netherlands: BRIN, BSN, BTW, Identiteitskaartnummer, Onderwijsnummer, Postcode
- 🇳🇴 Norway: Fodselsnummer, KontoNr, MVA, OrgNr
- 🇳🇿 New Zealand: BankAccount, IRD
- 🇵🇪 Peru: CUI, RUC
- 🇵🇱 Poland: NIP, PESEL, REGON
- 🇵🇹 Portugal: CC, NIF
- 🇵🇾 Paraguay: RUC
- 🇷🇴 Romania: CF, CNP, CUI, ONRC
- 🇷🇸 Serbia: PIB
- 🇷🇺 Russia: INN, OGRN
- 🇸🇪 Sweden: Orgnr, Personnummer, VAT
- 🇸🇬 Singapore: UEN
- 🇸🇮 Slovenia: DDV, EMSO
- 🇸🇰 Slovakia: DPH, RC
- 🇸🇲 San Marino: COE
- 🇸🇻 El Salvador: NIT
- 🇹🇷 Turkey: TCKimlik, VKN
- 🇺🇦 Ukraine: EDRPOU
- 🇺🇸 United States: ATIN, EIN, ITIN, PTIN, RTN, SSN
- 🇺🇾 Uruguay: RUT
- 🇻🇪 Venezuela: RIF
- 🇿🇦 South Africa: ID, TIN
Testing
The project incorporates PHPUnit. All formulas and checksums are deeply tested over boundary conditions spanning hundreds of assertions mirroring their native environments.
composer test
License
The MIT License (MIT). Please see License File for more information.
gbielbarbosa/stdnum-php 适用场景与选型建议
gbielbarbosa/stdnum-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 gbielbarbosa/stdnum-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gbielbarbosa/stdnum-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-16