PHPackages                             yivoff/spanish-nif - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. yivoff/spanish-nif

ActiveSymfony-bundle[Validation &amp; Sanitization](/categories/validation)

yivoff/spanish-nif
==================

Tool to verify and generate Spanish NIFs / Herramienta para verificar y generar NIFs de España

v1.0.0(4y ago)093MITPHPPHP &gt;=8.0

Since Jan 31Pushed 4y ago1 watchersCompare

[ Source](https://github.com/yivi/spanish-nif)[ Packagist](https://packagist.org/packages/yivoff/spanish-nif)[ RSS](/packages/yivoff-spanish-nif/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

NIF (DNI/NIE/CIF) checker &amp; generator
=========================================

[](#nif-dniniecif-checker--generator)

[![PHP Version Require](https://camo.githubusercontent.com/cb7a115c013a3420a455e5a00164c71cd5e1311038835754bfb55e0ca5b0ed3b/687474703a2f2f706f7365722e707567782e6f72672f7969766f66662f7370616e6973682d6e69662f726571756972652f706870)](https://packagist.org/packages/yivoff/spanish-nif)[![Latest Stable Version](https://camo.githubusercontent.com/ecce6cac754dba01e4c765607f1ad053daed6e4d5aa37201b08beb1b471e2d92/687474703a2f2f706f7365722e707567782e6f72672f7969766f66662f7370616e6973682d6e69662f76)](https://packagist.org/packages/yivoff/spanish-nif)[![Total Downloads](https://camo.githubusercontent.com/f0d9b8e90e78896dc4355852704b60e076a546cc913caf45ba9f250d1afdc091/687474703a2f2f706f7365722e707567782e6f72672f7969766f66662f7370616e6973682d6e69662f646f776e6c6f616473)](https://packagist.org/packages/yivoff/spanish-nif)[![Latest Unstable Version](https://camo.githubusercontent.com/17cd1487c40b70695f13c05b10e262799499da711450b1ab6a6ce46958f25dce/687474703a2f2f706f7365722e707567782e6f72672f7969766f66662f7370616e6973682d6e69662f762f756e737461626c65)](https://packagist.org/packages/yivoff/spanish-nif)[![License](https://camo.githubusercontent.com/a705f87127a97f28ced914a81d66da6b2a1724c7ba201f739b964f2b37299578/687474703a2f2f706f7365722e707567782e6f72672f7969766f66662f7370616e6973682d6e69662f6c6963656e7365)](https://packagist.org/packages/yivoff/spanish-nif)[![Tests](https://github.com/yivi/CommonMarkBundle/actions/workflows/bundle_tests.yaml/badge.svg)](https://github.com/yivi/CommonMarkBundle/actions/workflows/bundle_tests.yaml/badge.svg)[![codecov](https://camo.githubusercontent.com/08e209ef26bb58358296ff98a222d0a4e23463d6916aaf5385634af516afa997/68747470733a2f2f636f6465636f762e696f2f67682f796976692f7370616e6973682d6e69662f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d59525a4c4e3443414f52)](https://codecov.io/gh/yivi/spanish-nif)

Simple library to check that fiscal identifiers are valid according to Spanish legislation, and to generate valid fiscal identifiers.

Installation
------------

[](#installation)

```
composer require yivoff/nif-check

```

### Usage

[](#usage)

```
$checker = new \Yivoff\NifCheck\NifChecker();

// returns true if valid
$checker->verify($anyNif);
```

### NIF Generator

[](#nif-generator)

An utility is provided to generate valid NIFs, which could be useful for testing purposes or similar scenarios.

```
$generator = new \Yivoff\NifCheck\Generator\RandomNif();

// Generates a valid DNI
$validDni = $generator->generateDni();

// Generates a valid NIE
$validNie = $generator->generateNie();

// Generates a valid CIF
$validCif = $generator->generateCif();

// Generates a valid NIF (randomly DNI, NIF, or CIF)
$validNif = $generator->generate();
```

### Symfony Validator integration

[](#symfony-validator-integration)

The package provides a Symfony Validator attribute, which can simply be used like this:

```
use Yivoff\NifCheck\Validator\ValidNif;

class User
{
    #[ValidNif]
    public string $nif;
}
```

### fakerphp/faker Integration

[](#fakerphpfaker-integration)

The package also includes a Faker Provider.

```
$faker = Faker\Factory::create();
$faker->addProvider(new \Yivoff\NifCheck\FakerProvider\NifProvider($faker, new \Yivoff\NifCheck\Generator\RandomNif()));

// now you can fake NIFs

$faker->spanishDni();
$faker->spanishNie();
$faker->spanishCif();
$faker->spanishNif();
```

---

See:

1. [https://es.wikipedia.org/wiki/N%C3%BAmero\_de\_identificaci%C3%B3n\_fiscal](https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_fiscal)
2. [https://es.wikipedia.org/wiki/C%C3%B3digo\_de\_identificaci%C3%B3n\_fiscal](https://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1562d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0d85d0f1920fcb556200094ef25fe6d1c6c1540dac4b9118a0045d59b2a92bd?d=identicon)[yivi](/maintainers/yivi)

---

Top Contributors

[![yivi](https://avatars.githubusercontent.com/u/1815039?v=4)](https://github.com/yivi "yivi (19 commits)")

### Embed Badge

![Health badge](/badges/yivoff-spanish-nif/health.svg)

```
[![Health](https://phpackages.com/badges/yivoff-spanish-nif/health.svg)](https://phpackages.com/packages/yivoff-spanish-nif)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
