@concorde2k/ccdriverlicensevalidator

1.1.0 • Public • Published

Installation

npm i @concorde2k/ccDriverLicenseValidtor

Usage

Validate license number

Call the validator with the license number to be tested, and the state abbreviation. It will return TRUE if the format is valid, FALSE if it is not. For example:

const validator = require('@concorde2k/ccDriverLicenseValidtor');

// validate license number for the state of Pennsylvania
const result = validator.validateLicenseNumber('12345678', 'PA');
if( result) {
  // passed
} else {
  // failed
}

Get license format descriptions

The descriptions of a state's valid license formats can be retrieved (in order to display them to the end user, etc.).

const licenseFormats = validator.getLicenseFormatDescriptions('PA');

Override standard rules

If desired, pass an additional parameter with the validation rules:

const result = validator.validateLicenseNumber('12345678', 'PA', rules);
const licenseFormats = validator.getLicenseFormatDescriptions('PA', rules);

The rules object is a JSON object with a property for each state, consisting of a rule (a string containing a RegExp), and a description (an array of strings). For example:

{
  "AL": {
    "rule": "^[0-9]{1,8}$",
    "description": [
      "1-8 Numeric"
    ]
  },
  "AK": {
    "rule": "^[0-9]{1,7}$",
    "description": [
      "1-7 Numbers"
    ]
  },
  "AZ": {
    "rule": "(^[A-Z]{1}[0-9]{1,8}$)|(^[A-Z]{2}[0-9]{2,5}$)|(^[0-9]{9}$)",
    "description": [
      "1 Alpha + 1-8 Numeric",
      "2 Alpha + 2-5 Numeric",
      "9 Numeric"
    ]
  },
 .
 .
 .
}

Readme

Keywords

none

Package Sidebar

Install

npm i @concorde2k/ccdriverlicensevalidator

Weekly Downloads

8

Version

1.1.0

License

UNLICENSED

Unpacked Size

28 kB

Total Files

7

Last publish

Collaborators

  • kevin.concorde
  • nick.concorde2k
  • terry.concorde