PHPackages                             sevada/nie-validator - 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. sevada/nie-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

sevada/nie-validator
====================

Laravel validation rule for Spanish NIE (Número de Identidad de Extranjero) numbers

v2.0(4mo ago)02MITPHPPHP ^8.2CI passing

Since Jul 30Pushed 4mo agoCompare

[ Source](https://github.com/adavesik/nie-validator)[ Packagist](https://packagist.org/packages/sevada/nie-validator)[ Docs](https://github.com/sevada/nie-validator)[ RSS](/packages/sevada-nie-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (6)Used By (0)

Laravel NIF (NIE/DNI) Validator
===============================

[](#laravel-nif-niedni-validator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b31c591c6141b8253e826fad93322a887722255ec0b256164c9b224b6b697a5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7365766164612f6e69652d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sevada/nie-validator)[![Total Downloads](https://camo.githubusercontent.com/af3506918cc7319b37563c7d26fd207771b063ecee00a377ad8436b27c13976f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7365766164612f6e69652d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sevada/nie-validator)[![License](https://camo.githubusercontent.com/3655e8ad2158165a1834d6f13d9929d2667714df848853abe5258611f607814b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7365766164612f6e69652d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sevada/nie-validator)

A robust Laravel validation package for Spanish identification numbers:

- **NIE** (Número de Identidad de Extranjero)
- **DNI** (Documento Nacional de Identidad)

Validates according to the official algorithm regulated by **Real Decreto 1553/2005, Artículo 11**.

Features
--------

[](#features)

✅ **Combined Support** - Validates both NIE and DNI numbers
✅ **Accurate Validation** - Implements official Spanish algorithms
✅ **Flexible Input** - Accepts various formats (spaces, hyphens, mixed case)
✅ **Laravel Integration** - Seamless integration with Laravel's validator
✅ **Multilingual** - Built-in English and Spanish error messages
✅ **Type Safe** - Strict type declarations throughout
✅ **Well Tested** - 100+ test cases with comprehensive coverage
✅ **Zero Dependencies** - No external dependencies beyond Laravel

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x

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

[](#installation)

Install via Composer:

```
composer require sevada/nie-validator
```

The service provider will be automatically registered.

### Publishing Configuration (Optional)

[](#publishing-configuration-optional)

Publish the configuration file:

```
php artisan vendor:publish --tag=nif-config
```

Publish translation files:

```
php artisan vendor:publish --tag=nif-translations
```

Usage
-----

[](#usage)

### Basic Validation

[](#basic-validation)

Use the `nie` or `dni` validation rules in your validation logic:

```
use Illuminate\Http\Request;

public function store(Request $request)
{
    $validated = $request->validate([
        'nie_number' => ['required', 'nie'],
        'dni_number' => ['required', 'dni'],
    ]);

    // Numbers are valid!
}
```

### Using Rule Classes

[](#using-rule-classes)

You can also use the rule classes directly:

```
use Sevada\NifValidator\Rules\Nie;
use Sevada\NifValidator\Rules\Dni;

$request->validate([
    'nie_number' => ['required', new Nie],
    'dni_number' => ['required', new Dni],
]);
```

### Accepted Formats

[](#accepted-formats)

The validator automatically normalizes input and accepts various formats:

**NIE Examples:**

```
'X1234567L'      // ✅ Standard format
'Y-1234567-X'    // ✅ With hyphens
'Z 1234567 R'    // ✅ With spaces
```

**DNI Examples:**

```
'12345678Z'      // ✅ Standard format
'12345678-Z'     // ✅ With hyphens
'12345678 Z'     // ✅ With spaces
```

Configuration
-------------

[](#configuration)

The default configuration (`config/nif.php`):

```
return [
    // Official control letter sequence (DO NOT MODIFY)
    'control_letters' => str_split('TRWAGMYFPDXBNJZSQVHLCKE'),

    // Validation strictness
    'strict_format' => false, // Allow spaces and hyphens
];
```

Translations
------------

[](#translations)

### English (Default)

[](#english-default)

```
The :attribute is not a valid Spanish NIE (Número de Identidad de Extranjero).
The :attribute is not a valid Spanish DNI (Documento Nacional de Identidad).

```

### Spanish

[](#spanish)

```
El :attribute no es un NIE (Número de Identidad de Extranjero) válido.
El :attribute no es un DNI (Documento Nacional de Identidad) válido.

```

To use Spanish translations, set your application locale:

```
app()->setLocale('es');
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Security
--------

[](#security)

This package validates mathematical format but does not verify authenticity with official databases. See [SECURITY.md](SECURITY.md).

**Important**: Handle national ID numbers as sensitive personal data (GDPR).

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance74

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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

Every ~36 days

Total

5

Last Release

148d ago

Major Versions

v1.5.0 → v2.02025-12-21

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a3e5b0fdd072500b915e849105273d5a5e8f95650be66676b6aa448f7ef60e7?d=identicon)[adavesik](/maintainers/adavesik)

---

Top Contributors

[![adavesik](https://avatars.githubusercontent.com/u/4726494?v=4)](https://github.com/adavesik "adavesik (11 commits)")

---

Tags

laravelvalidatorvalidationidentityspanishspainNIE

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sevada-nie-validator/health.svg)

```
[![Health](https://phpackages.com/badges/sevada-nie-validator/health.svg)](https://phpackages.com/packages/sevada-nie-validator)
```

###  Alternatives

[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)[illuminatech/validation-composite

Allows uniting several validation rules into a single one for easy re-usage

184485.5k](/packages/illuminatech-validation-composite)[sadegh19b/laravel-persian-validation

A comprehensive Laravel validation package for Persian text, numbers, dates, and Iranian national identifiers

18293.8k1](/packages/sadegh19b-laravel-persian-validation)[stuyam/laravel-phone-validator

A phone validator for Laravel using the free Twilio phone lookup service.

2861.3k](/packages/stuyam-laravel-phone-validator)[mvdnbrk/gtin

GTIN / EAN / UPC Validation for Laravel

3148.6k1](/packages/mvdnbrk-gtin)

PHPackages © 2026

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