#nif #validation #nie #dni #spain

spain-vat-id

Spanish VAT ID numbers validation/verification

2 releases

0.1.2 Feb 22, 2024
0.1.1 Mar 27, 2022
0.1.0 Mar 27, 2022

#895 in Parser implementations

Download history 121/week @ 2024-02-18 35/week @ 2024-02-25 3/week @ 2024-03-03 1/week @ 2024-03-10 34/week @ 2024-03-24 31/week @ 2024-03-31

66 downloads per month

MIT license

7KB
95 lines

spain-vat-id

Build Crate Minimum rustc version

A dead simple crate for validating/verifying Spanish VAT ID numbers written in Rust.

This crate allows you to easily check and verify the following ID numbers:

  • Documento Nacional de Identidad (DNI)
  • Número de Identificación Fiscal (NIF)
  • Número de Identificación de Extranjero (NIE)

Installation

cargo add spain-vat-id

Functions

nif_check_digit(val: u32) -> char
is_valid_nie(v: &str) -> (bool, String)
is_valid_nif(v: &str) -> (bool, String)
// NIF checking
let nif = "9874`457T";
let (valid, explain) = is_valid_nif(nif);
if !valid{
    println!("{}", explain);
    // Not valid: Char '`' at position 5 is not a number
}

Contributors

Special thanks to @dev-ardi for a rework and improvements.

References

Dependencies

~295–750KB
~18K SLoC