ulabox / nif-validator
Yet another(?) PHP implementation of the spanish NIF validator
Installs: 105 648
Dependents: 1
Suggesters: 0
Security: 0
Stars: 25
Watchers: 4
Forks: 7
Open Issues: 1
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ~6.2
This package is not auto-updated.
Last update: 2024-11-13 17:32:47 UTC
README
A modern PHP 7.0+ Spanish NIF (Número de Indentifación Fiscal) validator.
Why another NIF validator?
Other NIF validators we saw either had really obscure code or just implemented a validator for the DNI/NIE, not the CIF.
Installation
Using Composer:
composer require ulabox/nif-validator
Usage
<?php use NifValidator\NifValidator; //CIF assert(NifValidator::isValid('B65410011')); //DNI assert(NifValidator::isValid('93471790C')); //NIE assert(NifValidator::isValid('X5102754C'));
Starting from version 1.1.x you can also separetely validate personal and entity nifs
<?php use NifValidator\NifValidator; //CIF assert(NifValidator::isValidEntity('B65410011')); //DNI assert(NifValidator::isValidPersonal('93471790C')); //NIE assert(NifValidator::isValidPersonal('X5102754C'));
Starting from version 1.2.x you can also separetely validate individual nif types
<?php use NifValidator\NifValidator; //CIF assert(NifValidator::isValidCif('B65410011')); //DNI assert(NifValidator::isValidDni('93471790C')); //NIE assert(NifValidator::isValidNie('X5102754C')); This validator does not strip or uppercase any character, it's your responsibility to previously filter the input.