Validate US driver's license numbers against all 50 state formats.
- Node.js: Supports Node 10 and above (
engines.node: ">=10.0.0"). - Format: CommonJS only; no build step required.
npm install @turnai/validate-us-drivers-licenseconst {
isValidUSLicense,
validateUSDriversLicense,
supportedStates,
driversLicenseRegex
} = require('@turnai/validate-us-drivers-license');Returns true or false.
license(string): License number to check (spaces and hyphens are stripped).state(string): Two-letter US state code (e.g.'CA','TX').
isValidUSLicense('1234567', 'AL'); // true
isValidUSLicense('12345678', 'AL'); // false
isValidUSLicense('1234567', 'ZZ'); // false (invalid state)Returns an object { valid: boolean, reasons: string[] }. Same inputs as above.
validateUSDriversLicense('1234567', 'AL');
// { valid: true, reasons: [] }
validateUSDriversLicense('12345678', 'AL');
// { valid: false, reasons: ['License must be 1-7 numbers', ...] }
validateUSDriversLicense('abc', 'NY');
// { valid: false, reasons: ['License and State must be Strings'] or state/format messages }Array of two-letter state codes.
supportedStates.includes('IL'); // trueObject keyed by state code; each value is an array of { regex, description } used for validation. For advanced or custom use only.
MIT