Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tax ID

Generate and validate tax identification numbers for 80 countries with specific checksum and format implementations.

Generate

Rust

#![allow(unused)]
fn main() {
use rand::thread_rng;
use idsmith::tax_id::GenOptions;

let mut rng = thread_rng();
let registry = idsmith::tax_ids();

// Random country
let result = registry.generate(&GenOptions::default(), &mut rng).unwrap();

// Specific country
let opts = GenOptions { country: Some("IN".to_string()), holder_type: None };
let india = registry.generate(&opts, &mut rng).unwrap();
// india.country_code → "IN"
// india.name         → "PAN"
// india.code         → "ABCDE1234F"

// India PAN with holder type
let opts = GenOptions {
    country: Some("IN".to_string()),
    holder_type: Some("C".to_string()),  // C = Company
};
let pan = registry.generate(&opts, &mut rng).unwrap();
}

Python

import idsmith

result = idsmith.TaxId.generate()                          # random country
india = idsmith.TaxId.generate(country="IN")               # specific country
print(india["name"])  # PAN
print(india["code"])  # ABCDE1234F

# India PAN with holder type
pan = idsmith.TaxId.generate(country="IN", holder_type="C")

JavaScript

const { TaxId } = require('idsmith');

const result = TaxId.generate();           // random country
const india = TaxId.generate('IN');        // specific country
console.log(india.name);  // PAN
console.log(india.code);  // ABCDE1234F

// India PAN with holder type
const pan = TaxId.generate('IN', { holderType: 'C' });

Validate

Rust

#![allow(unused)]
fn main() {
idsmith::tax_ids().validate("IN", "ABCDE1234F");   // true
idsmith::tax_ids().validate("BR", "12345678909");   // true
}

Python

idsmith.TaxId.validate("IN", "ABCDE1234F")  # True

JavaScript

TaxId.validate('IN', 'ABCDE1234F');  // true

Checksum-Verified Countries

CountryFormatChecksum
INPAN (10 chars, AAAAA0000A)Pattern validation, holder_type option (P/C/H/F/A/T/B/L/J/G)
USTIN (9 digits)Area number constraints (no 000, 666, 9xx)
GBUTR (10 digits)Weighted mod-11 checksum
DESteuer-IdNr (11 digits)ISO 7064 mod 11,10
FRNIF (13 digits)Mod-97 checksum
BRCPF (11 digits)Mod-11 checksum (two check digits)
AUTFN (9 digits)Weighted checksum (mod 11)
CASIN (9 digits)Luhn checksum
JPMy Number (12 digits)Mod-11 weighted checksum
CNUSCI (18 chars alphanumeric)Mod-31 weighted checksum
ITPartita IVA (11 digits)Luhn-variant checksum
ESNIF (8 digits + letter)Mod-23 check letter
NLBSN (9 digits)11-check (weighted sum)
SEPersonnummer (10 digits)Luhn checksum
KRBRN (10 digits)Weighted check digit
SGTax Ref (9 chars, NRIC format)Weighted mod-11 with check letter
ZATax Number (10 digits)Luhn checksum
MXRFC (12-13 chars)Mod-11 alphanumeric check digit