Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex for vehicle identification number (VIN)
Regex pattern · validation

Regex for vehicle identification number (VIN)

Regex for VIN number: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /^[A-HJ-NPR-Z0-9]{17}$/ as a vehicle identification number (VIN) regex. It matches "1HGCM82633A004352" and "WVWZZZ3CZWE123456", and rejects "1HGCM82633A00435" and "1HGCM82633A0043I2". North American VINs also have a check digit in position 9 that regex cannot verify.

Last updated · Maintained by FreeAIToolz · How we test

/^[A-HJ-NPR-Z0-9]{17}$/
  • 1HGCM82633A004352matches
  • WVWZZZ3CZWE123456matches
  • 1HGCM82633A00435no match
  • 1HGCM82633A0043I2no match
  • 1HGCM82633A0O4352no match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
[A-HJ-NPR-Z0-9]letters except I, O and Q, plus digits
{17}$exactly 17 characters

Examples

InputResult
1HGCM82633A004352✓ Matches
WVWZZZ3CZWE123456✓ Matches
1HGCM82633A00435✗ No match
1HGCM82633A0043I2✗ No match
1HGCM82633A0O4352✗ No match

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

North American VINs also have a check digit in position 9 that regex cannot verify.

When to use this pattern

Automotive dealer and insurance forms, and VIN decoders.

Use it in your language

JavaScript

const re = /^[A-HJ-NPR-Z0-9]{17}$/;
re.test(input); // true or false

Python

import re
pattern = re.compile(r'^[A-HJ-NPR-Z0-9]{17}$')
bool(pattern.search(value))

PHP

$ok = preg_match('~^[A-HJ-NPR-Z0-9]{17}$~', $value) === 1;

Java

Pattern pattern = Pattern.compile("^[A-HJ-NPR-Z0-9]{17}$");
boolean ok = pattern.matcher(value).find();

Go

re := regexp.MustCompile(`^[A-HJ-NPR-Z0-9]{17}$`)
ok := re.MatchString(value)

More regex patterns

Frequently asked questions

What is the regex for vehicle identification number (VIN)?
/^[A-HJ-NPR-Z0-9]{17}$/. North American VINs also have a check digit in position 9 that regex cannot verify.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It also works in Go’s RE2 engine.
Why does the pattern start with ^ and end with $?
They anchor the match to the whole string, so "abc1HGCM82633A004352xyz" cannot pass just because it contains a valid part. To search for matches inside longer text, remove ^ and $ (use \b where word boundaries help) and add the g flag.