dni
Validate Spanish DNI and NIE identification numbers.
- DNI (Documento Nacional de Identidad) — 8 digits + a check letter.
- NIE (Número de Identidad de Extranjero) —
X/Y/Z+ 7 digits + a check letter.
A faithful Rust port of the algorithms used by
python-stdnum.
- Zero dependencies,
#![no_std] is_valid,validate,calc_check_digit,compactfor both DNI and NIE- Accepts
-/space separators and lower-case input - Differential-tested against
python-stdnum(60k cases)
Install
[]
= "0.1"
Usage
use ;
// DNI:
assert!;
assert!; // wrong check letter
assert_eq!;
assert_eq!;
// NIE:
assert!;
assert_eq!;
The check letter is "TRWAGMYFPDXBNJZSQVHLCKE"[number % 23]; for a NIE the leading X/Y/Z
is first replaced with 0/1/2.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.