3.1.1 • Published 2 years ago

driver-license-validator v3.1.1

Weekly downloads
1,686
License
MIT
Repository
github
Last release
2 years ago

NPM Version CI codecov

Driver License Validator

Validate driver license numbers. Formats based on https://ntsi.com/drivers-license-format/.

Table of Contents

Installation

npm install driver-license-validator --save

Usage

import { getMatches, isValid } from 'driver-license-validator';

isValid('A1234567');
// => true

isValid('invalid_dl');
// => false

getMatches('A1234567');
// => [
//   { description: '1 letter followed by 1-8 numbers', state: 'AZ' },
//   { description: '1 letter followed by 7 numbers', state: 'CA' },
//   { description: '1 letter followed by 5-9 numbers', state: 'MO' },
//   { description: '1 letter followed by 6-8 numbers', state: 'NE' },
//   { description: '1 letter followed by 7 numbers', state: 'NY' },
//   { description: '1 letter followed by 4-8 numbers', state: 'OH' }
// ]

getMatches('A1234567', { states: 'NY' });
// => [
//   { description: '1 letter followed by 7 numbers', state: 'NY' }
// ]

getMatches('A1234567', { states: ['NY', 'OH'] });
// => [
//   { description: '1 letter followed by 7 numbers', state: 'NY' },
//   { description: '1 letter followed by 4-8 numbers', state: 'OH' }
// ]

getMatches('A123456789', { country: 'CA' });
// => [
//   { description: '1 letter followed by 9 numbers', state: 'NL' }
// ]

getMatches('invalid_dl');
// => null

Options:

OptionTypeDescriptionDefault
countrystringCountry to use.US
statesstring or string[]State(s) to filter results to.n/a
ignoreCasebooleanTrue to ignore case.false

Development

npm install
npm run build