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

Passport

Generate and validate passport numbers for 79 countries with specific format implementations.

Generate

Rust

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

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

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

// Specific country
let opts = GenOptions { country: Some("US".to_string()) };
let us = registry.generate(&opts, &mut rng).unwrap();
// us.country_code → "US"
// us.name         → "Passport"
// us.code         → "123456789"
}

Python

import idsmith

result = idsmith.Passport.generate()                   # random country
us = idsmith.Passport.generate(country="US")           # specific country
print(us["name"])  # Passport
print(us["code"])  # 123456789

JavaScript

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

const result = Passport.generate();      // random country
const us = Passport.generate('US');      // specific country
console.log(us.name);  // Passport
console.log(us.code);  // 123456789

Validate

Rust

#![allow(unused)]
fn main() {
idsmith::passports().validate("US", "123456789");   // true
idsmith::passports().validate("DE", "C01X00T47");   // true
}

Python

idsmith.Passport.validate("US", "123456789")  # True

JavaScript

Passport.validate('US', '123456789');  // true

Country-Specific Implementations

CountryFormatDescription
IN8 chars (1 alpha + 7 digits)Indian passport number
US9 digitsUS passport number
GB9 digitsBritish passport number
DE9 chars (C + 8 alphanumeric)German Reisepass with serial check digit
FR9 chars (2 alpha + 7 digits)French passport number
BR8 chars (2 alpha + 6 digits)Brazilian passport number
AU8 chars (1 alpha + 7 digits)Australian passport number
CA8 chars (2 alpha + 6 digits)Canadian passport number
JP9 chars (2 alpha + 7 digits)Japanese passport number
CN9 chars (E/G + 8 digits)Chinese passport (E for ordinary, G for official)
IT9 chars (2 alpha + 7 digits)Italian passaporto
ES9 chars (3 alpha + 6 digits)Spanish pasaporte
NL9 chars (2 alpha + 7 digits)Dutch paspoort
SE8 digitsSwedish pass
KR9 chars (M/S + 8 digits)Korean passport (M = regular, S = official)
SG9 chars (E + 7 digits + 1 alpha)Singapore passport
ZA9 chars (1 alpha + 8 digits)South African passport
MX10 digitsMexican pasaporte