dni 0.1.0

Validate Spanish DNI and NIE identification numbers. A faithful port of the python-stdnum algorithms. Zero deps, no_std.
Documentation
  • Coverage
  • 100%
    14 out of 14 items documented3 out of 10 items with examples
  • Size
  • Source code size: 27.73 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 245.28 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/dni
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

dni

All Contributors

crates.io docs.rs CI license

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, compact for both DNI and NIE
  • Accepts -/space separators and lower-case input
  • Differential-tested against python-stdnum (60k cases)

Install

[dependencies]
dni = "0.1"

Usage

use dni::{is_valid, validate, calc_check_digit};

// DNI:
assert!(is_valid("12345678Z"));
assert!(!is_valid("12345678A"));         // wrong check letter
assert_eq!(validate("12345678-z").unwrap(), "12345678Z");
assert_eq!(calc_check_digit("12345678").unwrap(), 'Z');

// NIE:
assert!(dni::nie::is_valid("X1234567L"));
assert_eq!(dni::nie::validate("x-2482300-w").unwrap(), "X2482300W");

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.