https://github.com/jsgm/spain-vat-id
Spanish VAT ID numbers validation/verification
https://github.com/jsgm/spain-vat-id
dni nie nif spain validation vat
Last synced: 5 months ago
JSON representation
Spanish VAT ID numbers validation/verification
- Host: GitHub
- URL: https://github.com/jsgm/spain-vat-id
- Owner: jsgm
- License: mit
- Created: 2022-03-27T02:57:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-10-26T18:02:00.000Z (10 months ago)
- Last Synced: 2025-10-27T10:36:51.410Z (9 months ago)
- Topics: dni, nie, nif, spain, validation, vat
- Language: Rust
- Homepage: https://crates.io/crates/spain-vat-id
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spain-vat-id

[](https://crates.io/crates/spain-vat-id)


A dead simple crate for validating/verifying Spanish VAT ID numbers written in [Rust](https://rust-lang.org).
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
```rust
nif_check_digit(val: u32) -> char
is_valid_nie(v: &str) -> (bool, String)
is_valid_nif(v: &str) -> (bool, String)
```
```rust
// 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](https://github.com/dev-ardi) for a rework and improvements.
## References
- https://en.wikipedia.org/wiki/VAT_identification_number
- https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_fiscal
- https://es.wikipedia.org/wiki/N%C3%BAmero_de_identidad_de_extranjero
- http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie