If you build invoicing, onboarding or checkout forms for Indian businesses, you'll ask for a GSTIN sooner or later. Users mistype them all the time: a swapped letter, a missing digit, an O instead of a 0.
You can't confirm that a GSTIN is real and active without checking the GST portal. But you can catch most typos instantly in the browser, because every GSTIN ends with a check character calculated from the other 14. Here's how.
What a GSTIN looks like
A GSTIN has 15 characters:
| Position | What it is |
|---|---|
| 1–2 | State code (digits) |
| 3–12 | The holder's PAN (5 letters, 4 digits, 1 letter) |
| 13 | Entity number for that PAN in that state (1–9, then A–Z) |
| 14 | Currently always Z |
| 15 | Check character |
Step 1: check the shape
A regex handles the structure:
const GSTIN_SHAPE = /^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/; That rejects the wrong length, letters where digits should be, and so on. It can't catch a typo that still fits the pattern. That's what the check character is for.
Step 2: compute the check character
The 15th character comes from a weighted sum over the first 14, in base 36 (digits 0–9 then letters A–Z):
const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; function checkChar(first14) { let sum = 0; for (let i = 0; i < 14; i++) { const value = CHARS.indexOf(first14[i]); const product = value * (i % 2 === 0 ? 1 : 2); sum += Math.floor(product / 36) + (product % 36); } return CHARS[(36 - (sum % 36)) % 36]; } Each character's value is multiplied by 1 or 2, alternating. The product is split into its base-36 "tens" and "units", which are added to the running sum. The check character is whatever brings the total up to a multiple of 36.
Step 3: put it together
function validateGstin(input) { const gstin = String(input).trim().toUpperCase(); if (gstin.length !== 15) return { ok: false, reason: 'A GSTIN has 15 characters' }; if (!GSTIN_SHAPE.test(gstin)) return { ok: false, reason: 'The format does not match a GSTIN' }; const expected = checkChar(gstin.slice(0, 14)); if (gstin[14] !== expected) return { ok: false, reason: `Check character should be ${expected}` }; return { ok: true, stateCode: gstin.slice(0, 2), pan: gstin.slice(2, 12) }; } Trying it with a made-up GSTIN:
validateGstin('27ABCDE1234F1Z0'); // { ok: true, stateCode: '27', pan: 'ABCDE1234F' } validateGstin('27abcde1234f1z0 '); // { ok: true, ... } (trimmed and upper-cased first) validateGstin('27ABCDE1234F1Z5'); // { ok: false, reason: 'Check character should be 0' } validateGstin('27ABCDE1234F1Z'); // { ok: false, reason: 'A GSTIN has 15 characters' } I tested all of this in Node 24 before posting.
A few practical notes
- Normalise first. Trim and upper-case before validating, and store the normalised value.
- Be kind in the error message. "Check character should be 0" is accurate but not friendly. In a real form, "This GSTIN doesn't look right. Please check it against your registration certificate" is better. Keep the detailed reason for your logs.
- Valid doesn't mean active. A GSTIN can pass every check and still be cancelled or belong to someone else. If it matters (say, before you issue a B2B tax invoice), confirm it on the GST portal.
- Don't validate GSTINs you don't need. Plenty of freelancers aren't registered at all, so make the field optional unless your use case really requires it.
Where this fits
If you're building something for Indian freelancers, the GSTIN field is usually the first sign of a bigger question: whether the user needs to be registered at all. Vobero has a clear guide to GST registration for Indian freelancers you can point users to. And if you'd rather see the whole invoice side of things working, their free invoice generator is a good reference for which fields matter.
Have you run into other ID formats with check digits worth validating client-side? Tell us in the comments.

