Skip to content

Instantly share code, notes, and snippets.

@lipe-dev
Last active March 9, 2023 11:19
Show Gist options
  • Save lipe-dev/4468b0fcc4c85acaa7bca9db534a9779 to your computer and use it in GitHub Desktop.
Save lipe-dev/4468b0fcc4c85acaa7bca9db534a9779 to your computer and use it in GitHub Desktop.
Regexes for all US states and Canada provinces driver licenses. Each one has their own rules.
// Some info based on: https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-canada-drivers-license-number?view=o365-worldwide
const canadaDLNumberPatterns = {
Alberta: /\d{6}-\d{3}|\d{5,9}/,
"British Columbia": /\d{7}/,
Manitoba: /\w{2}-?\w{2}-?\w{2}-?\w\d{3}\w{2}/,
"New Brunswick": /\d{5,7}/,
"Newfoundland and Labrador": /\w\d{9}/,
"Nova Scotia": /\w{5}-?[0123]\d[01]\d{6}/,
Ontario: /\w\d{4}-?\d{5}\d[0156]\d[0123]\d/,
"Prince Edward Island": /\d{5,6}/,
Quebec: /\w\d{12}/,
Saskatchewan: /\d{8}/,
"Northwest Territories": /\d{6}/,
Nunavut: /.*/, // I was unable to find a reliable source. Seems to be \d{5,6}
Yukon: /\d{1,6}/,
};
// Based on: https://ntsi.com/drivers-license-format/
const usDLNumberPatterns = {
Alabama: /\d{1,8}/,
Alaska: /\d{1,7}/,
Arizona: /[\w\d]\d{8}/,
Arkansas: /\d{4,9}/,
California: /\w\d{7}/,
Colorado: /\d{9}|\w\d{3,6}|\w{2}\d{2,5}/,
Connecticut: /\d{9}/,
Delaware: /\d{7}/,
Florida: /\w\d{12}/,
Georgia: /\d{7,9}/,
Hawaii: /\w\d{8}|\d{9}/,
Idaho: /\w{2}\d{6}\w|\d{9}/,
Illinois: /\w\d{11,12}/,
Indiana: /\w\d{9}|\d{10}/,
Iowa: /\d{9}|\d{3}\w{2}\d{4}/,
Kansas: /\w\d\w\d\w|\w\d{8}|\d{9}/,
Kentucky: /\w\d{8,9}|\d{9}/,
Louisiana: /\d{9}/,
Maine: /\d{7}|\d{7}\w|\d{8}/,
Maryland: /\w\d{12}/,
Massachusetts: /\w\d{8}|\d{9}/,
Michigan: /\w\d{10}|\w\d{12}/,
Minnesota: /\w\d{12}/,
Mississippi: /\d{9}/,
Missouri: /\d{3}\w\d{6}|\w\d{5,9}|\w\d{6}[rR]|\d{8}\w{2}|\d{9}\w?/,
Montana: /\w\d{8}|\d{9}|\d{13,14}/,
Nebraska: /\w\d{6,8}/,
Nevada: /\d{9,10}|\d{12}|[xX]\d{8}/,
"New Hampshire": /\d{2}\w{3}\d{5}/,
"New Jersey": /\w\d{14}/,
"New Mexico": /\d{8,9}/,
"New York": /\w\d{7}|\w\d{18}|\d{8,9}|\d{16}|\w{8}/,
"North Carolina": /\d{1,12}/,
"North Dakota": /\w{3}\d{6}|\d{9}/,
Ohio: /\w{1}\d{4,8}|\w{2}\d{3,7}|\d{8}/,
Oklahoma: /\w?\d{9}/,
Oregon: /\d{9}/,
Pennsylvania: /\d{8}/,
"Rhode Island": /\d{7}|\w\d{6}/,
"South Carolina": /\d{5,11}/,
"South Dakota": /\d{6,10}|\d{12}/,
Tennessee: /\d{7,9}/,
Texas: /\d{7,8}/,
Utah: /\d{4,10}/,
Vermont: /\d{8}|\d{7}[aA]/,
Virginia: /\w\d{8,11}|\d{9}/,
Washington: /(?=.{12}$)\w{1,7}[\w\d]+/,
"West Virginia": /\d{7}|\w{1,2}\d{5,6}/,
Wisconsin: /\w\d{13}/,
Wyoming: /\d{9,10}/,
"District of Columbia": "d{7}|d{9}",
};
@lipe-dev
Copy link
Author

lipe-dev commented Mar 7, 2023

If anyone has info form a reputable source about the Northwest Territories, Nunavut and Yukon rules, I will include them. In the meanwhile, I'll try reaching out to the respective government agencies.

@lipe-dev
Copy link
Author

lipe-dev commented Mar 8, 2023

Yukon confirmed to be 1 to 6 digits by a government official.
image

@lipe-dev
Copy link
Author

lipe-dev commented Mar 8, 2023

NWT confirmed to be 6 digits only by a government official.
image

@george-silva
Copy link

Commercial Driver Licenses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment