vat_id_validator

Crates.iovat_id_validator
lib.rsvat_id_validator
version0.2.0
created_at2025-12-13 20:21:31.156601+00
updated_at2025-12-13 21:09:32.89979+00
descriptionA comprehensive library for validating VAT numbers, including format and checksum verification for 30+ countries.
homepage
repositoryhttps://github.com/roksprogar/vat-id-validator
max_upload_size
id1983374
size164,537
Rok Sprogar (roksprogar)

documentation

https://docs.rs/vat_id_validator

README

Vat ID validator (EU and non-EU countries, with checksums)

Validate VAT numbers for European Union countries (and several other countries), with checksum verification.

Many libraries only check if a VAT number looks right (regex). vat_id_validator checks if it is right.

It verifies the checksum of the VAT number using country-specific algorithms (Luhn, Modulo 97, weighted sums, etc.). This means you can catch typos, transposed digits, and fake numbers instantly, without making a single network request to flaky government APIs like VIES.

Key Benefits

  • โšก Instant & Offline: Zero network latency. No VIES downtime. Works everywhere.
  • ๐Ÿงฎ Mathematical Verification: Catches invalid numbers that regex would pass (e.g., typos).
  • ๐Ÿ›ก๏ธ Type-Safe Rust: Built for speed and reliability.
  • ๐ŸŒ Multi-Country: Supports 30+ countries including EU, UK, Norway, Switzerland, Serbia, Russia, and Brazil.

๐Ÿš€ Key Features

1. Explicit Country Validation

Don't guess! If you know the country, validate strictly against it.

// O(1) lookup - 2.3x faster than standard check!
let result = check_vat_by_country("GB999000005", "GB");

2. Serde Support

Enable the serde feature to serialize results straight to JSON.

{
  "value": "GB999000005",
  "is_valid": true,
  "is_valid_format": true,
  "is_supported_country": true,
  "country_name": "United Kingdom"
}

3. Country Identifier (GeoGuesser Mode)

Got a number but don't know where it's from?

use vat_id_validator::identify_country;

// Returns valid results for ALL matching countries
let matches = identify_country("999000005"); 

// Matches:
// - United Kingdom (it tries adding "GB" automatically!)
// - Any other country where "999000005" is valid

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
vat_id_validator = { version = "0.2.0", features = ["serde"] }

Usage

use vat_id_validator::check_vat;

fn main() {
    // Valid UK VAT number
    assert!(check_vat("GB999000005").is_valid);

    // Invalid format
    assert!(!check_vat("GB123").is_valid);

    // Valid format but invalid checksum
    assert!(!check_vat("GB999999974").is_valid);
}

๐ŸŽ๏ธ Benchmarks

We take "instant" seriously.

Operation Time
check_vat (heuristic) ~1.06 ยตs
check_vat_by_country (direct) ~460 ns

Measured on M-series Mac. Your mileage may vary, but it will be fast.

Supported Countries

  • Andorra (AD)
  • Austria (AT)
  • Belgium (BE)
  • Brazil (BR)
  • Bulgaria (BG)
  • Croatia (HR)
  • Cyprus (CY)
  • Czech Republic (CZ)
  • Denmark (DK)
  • Estonia (EE)
  • Finland (FI)
  • France (FR)
  • Germany (DE)
  • Greece (GR)
  • Hungary (HU)
  • Ireland (IE)
  • Italy (IT)
  • Latvia (LV)
  • Lithuania (LT)
  • Luxembourg (LU)
  • Malta (MT)
  • Netherlands (NL)
  • Norway (NO)
  • Poland (PL)
  • Portugal (PT)
  • Romania (RO)
  • Russia (RU)
  • Serbia (RS)
  • Slovakia (SK)
  • Slovenia (SI)
  • Spain (ES)
  • Sweden (SE)
  • Switzerland (CH)
  • United Kingdom (GB)

License

MIT / Apache-2.0

Commit count: 0

cargo fmt