VIN (vehicle identification number) validator and input directive
1 person uses it
Author: 108414?v=3 rfink


VIN (vehicle identification number) validator and input directive. See VIN Wikipedia for information on VIN

Vehicle VINs use a check digit system to determine if the VIN is valid. VINs past 1980 must have 17 digits, and they must be alphanumeric and NOT contain the letters I, Q, or O (likely to avoid confusion with numbers).


First, you can add to your bower.json if you want to use that:

Angular-vin only requires angular (in production). To use in your angular app, add "angular-vin" to your dependencies:

Then, you can add "vin-input" directive inside your html. You can also specify a callback from scope to call when the VIN is successfully input and validate. Also, the module sets 4 different validity properties depending on what is invalid (see below)

The directive prevents invalid characters, adds a max length to the input element, and automatically converts input to upper-case.

Controller code:

You can opt out of using the directive and simply use the service.

For the sake of completeness, the vinValidatorService exports additional properties relating to VIN validation. These are: + vinLength - equal to 17 + checkDigitIndex - equal to 8 (9th position in the VIN) + invalidChars - 'OQI' + regEx - "[A-HJ-NPR-Z0-9]{17}" + replaceRegEx - "[A-HJ-NPR-Z0-9]" + characterMap - map of alphabet characters to numeric value + weights - weights based on index position

comments powered by Disqus
This page was last updated about 3 years ago.