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

Driver’s License

Generate and validate driver’s license numbers for 79 countries with specific checksum and format implementations.

Generate

Rust

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

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

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

// Specific country
let opts = GenOptions { country: Some("US".to_string()), state: None };
let us = registry.generate(&opts, &mut rng).unwrap();
// us.country_code → "US"
// us.name         → "Driver's License"
// us.code         → "A123456789012"
}

Python

import idsmith

result = idsmith.DriverLicense.generate()                   # random country
us = idsmith.DriverLicense.generate(country="US")           # specific country
print(us["name"])  # Driver's License
print(us["code"])  # A123456789012

JavaScript

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

const result = DriverLicense.generate();      // random country
const us = DriverLicense.generate('US');      // specific country
console.log(us.name);  // Driver's License
console.log(us.code);  // A123456789012

Validate

Rust

#![allow(unused)]
fn main() {
idsmith::driver_licenses().validate("US", "A123456789012");  // true
idsmith::driver_licenses().validate("IN", "KA0120190012345"); // true
}

Python

idsmith.DriverLicense.validate("US", "A123456789012")  # True

JavaScript

DriverLicense.validate('US', 'A123456789012');  // true

Country-Specific Implementations

CountryFormatDescription
IN15 chars ({STATE}{RTO}{YEAR}{SERIAL})Indian DL with state, RTO code, year, and serial
US13 chars (1 alpha + 12 digits)US driver’s license number
GB16 chars DVLA alphanumericDVLA format with name-derived characters
DE11 chars alphanumericGerman Führerschein number
FR12 chars (2 alpha + 10 digits)French permis de conduire
BR11 digits with 2 check digits (CNH)Brazilian CNH with mod-based check digits
AU8-10 chars alphanumericAustralian state-issued license
CA13 chars (1 alpha + 12 digits)Canadian provincial license
JP12 digitsJapanese driver’s license number
CN12 digitsChinese driver’s license number
IT10 chars (2 alpha + 7 digits + 1 alpha)Italian patente di guida
ES9 chars (8 digits + check letter)Spanish DNI-format with mod-23 check
NL10 digitsDutch rijbewijs number
SE10 digits (personnummer format)Swedish körkort with Luhn checksum
KR12 digits (region + year + serial)Korean driver’s license with region codes
SG9 chars (NRIC format)Singapore license with weighted checksum
ZA13 digits (ID number format)South African license with Luhn checksum
MX12 chars (CURP-derived)Mexican licencia de conducir