vin validator

Validate an US VIN (Vehicle Identification Number)

Options

Using with form field
The HTML attributes are used to set the validator options via the Declarative plugin
NameHTML attributeTypeDescription
messagedata-fv-vin___messageStringThe error message
Using the ES6 module
// You might need to change the importing path
import { vin } from '/vendors/@form-validation/cjs/validator-vin';
const result = vin().validate({
value: ...,
options: {
message: ...,
},
});
/*
result is an object of
{
valid: true or false,
message: The error message
}
*/
Using the npm package
  • Install the validator package:
$ npm install @form-validation/validator-vin
  • Use the vin validator:
import { vin } from '@form-validation/validator-vin';
const result = vin().validate({
value: ...,
options: {
message: ...,
},
});

Basic example

vin validator

NPM package example

The following snippet shows how to use the vin validator with the npm package:
import { vin } from '@form-validation/validator-vin';
const res1 = vin().validate({
value: '192.168.1.1',
options: {
message: 'The value is not valid IP address',
},
});
// res1.valid === true
const res2 = vin().validate({
value: 'JTMKF4DV5B5309254',
options: {
message: 'The value is not valid VIN',
},
});
// res2.valid === false

Changelog

v2.0.0
  • Add the npm package