About this Post

A glimpse into how we perform Tesla VIN lookups with JavaScript using our in-house, standards-based tooling.

Next week, our JS Working Group crew will be hosting a Frontend Meetup covering our in-house internationalization ecosystem. As I've been preparing for the talk, I thought it would be fun to share a few details here, notably on one of the topics we'll be covering: decoding and validating a Tesla VIN.

JS Working Group Presents: Internationalization Standards at Tesla

Our new, centralized VIN decoder and validator is a great example of one of our tooling solutions to build standards-based features that impact our customers, developers and various business partners across the globe.

Definition: Under NHTSA's regulations, each motor vehicle must contain a vehicle identification number, also known as a VIN, which is a 17-character number that encodes specific information about the particular vehicle.

Like with our other in-house JavaScript libraries and tools, this VIN solution is based on standards (beyond and in parallel to Tesla's contextual rules) and is part of our Tesla identification number (ID) tooling ecosystem.

We offer all of our JavaScript libraries in both CommonJS and ES module formats.

Since part of our business is vehicles, e.g. manufacturing, selling and accepting trade-ins, we need a reliable way to validate VINs and look up information about them both internally and externally.

// Example invalid VIN unit test it('returns falsy with a VIN of 18 characters', () => { const vin = '5YJ***************'; const result = validateVIN(vin); expect(vin).toHaveLength(18); expect(result).toBeFalsy(); });

// Example invalid VIN due to prefix not matching Tesla's it('returns falsy with a non-Tesla VIN', () => { // A subset of Tesla VINs start with 5YJ const vin = 'JTD**************'; const result = isTeslaVIN(vin); expect(result).toBeFalsy(); });

For the curious, underneath the hood, we use a RegEx to validate that a specified VIN is a 1) valid VIN and 2) Tesla VIN. The RegEx is based on the NHTSA's VIN standard where we validate the VIN's length, prefix, check digit, etc.

Tip: The first three characters of a VIN represent the World Manufacturer Identifier (WMI), which is a unique identifier for the manufacturer of the vehicle, e.g. Tesla.

Offering this type of critical functionality to teams across the company in a way that is consistent, easy-to-use and well-documented removes redundancy, increases efficiency and reduces the risk of (costly) errors.

I'm particularly excited about this meetup — I think it'll be a great opportunity for folks to learn more about our effort to standardize our tooling ecosystem and how to leverage it all to build phenomenal digital experiences. In addition to our Tesla identification number (ID) tooling ecosystem, we'll also be covering i18n phone numbers, CLDR, BCP 47, the JS Intl namespace and more, including how others at the company can contribute to our innersource initiative.

If you'd like to learn more about our efforts on this front, don't hesitate to reach out. I'd love to chat!

I have worked with Manny many times on international projects. In my experience, always professional and responsive, which is what's required when collaborating over different time zones.

John Sayers, Product Management and Digital Producer @ Tesla
Product Management and Digital Producer @ Tesla