https://github.com/jsgm/spain-vat-id
Spanish VAT ID numbers validation/verification
https://github.com/jsgm/spain-vat-id
dni nie nif spain
Last synced: 4 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 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-22T20:25:37.000Z (over 1 year ago)
- Last Synced: 2025-07-05T04:18:47.785Z (4 months ago)
- Topics: dni, nie, nif, spain
- Language: Rust
- Homepage: https://crates.io/crates/spain-vat-id
- Size: 17.6 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)
[](https://github.com/rust-random/rand#rust-version-requirements)
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