Skip to content

ulabox/nif-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nif-validator

Build Status

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages