GSTIN Validator Code Generator
Bad GSTINs on customer and vendor masters cause rejected e-invoices and ITC problems later. This generator gives you a small Python function that checks the pattern and the checksum, so your import scripts and ERP integrations can reject typos early.
Fill in
Python function
import re
GSTIN_RE = re.compile(r"^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$")
CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def gstin_checksum(first14):
total = 0
for i, ch in enumerate(first14):
value = CHARS.index(ch) * (1 if i % 2 == 0 else 2)
total += value // 36 + value % 36
return CHARS[(36 - total % 36) % 36]
def is_valid_gstin(gstin):
g = gstin.strip().upper()
if not GSTIN_RE.match(g):
return False
return gstin_checksum(g[:14]) == g[14]
print(is_valid_gstin("27AAPFU0939F1ZV"))What each part of a GSTIN means
| Position | Meaning | Example |
|---|---|---|
| 1-2 | State code | 27 |
| 3-12 | PAN of the taxpayer | AAPFU0939F |
| 13 | Registration number for the same PAN in the state | 1 |
| 14 | Default letter Z | Z |
| 15 | Checksum character | V |
A passing check only proves the format and checksum are consistent. It does not prove the GSTIN is active. Confirm status through the GST portal search or an authorised API before relying on it.
Master data quality review
Optional expert review of GSTIN and PAN quality checks on your customer and vendor masters.
Optional. The tool and every export work without this. No spam.
How to use it
Set the function name, paste the sample GSTIN you want to test, and copy the code into your data load script. Run it over the party master export from Tally, Busy, Marg or Zoho Books and review the rows that return False. Fix those at source before migration or e-invoice onboarding.
How the checksum works
Each of the first 14 characters is mapped to a value from 0 to 35, with digits first and then letters A to Z. Characters in even positions are multiplied by 1 and odd ones by 2. For each product the quotient and remainder after dividing by 36 are added up. The check character is the value of 36 minus the total modulo 36, taken modulo 36 again.
- The regex checks length, state digits, PAN pattern and the letter Z.
- The checksum catches most single character typos.
- Neither check shows whether the registration is active.
Where to use it in an ERP
Run it as a pre-save validation in a custom script or integration layer. SAP Business One India, Zoho Books and Tally each have their own built-in GSTIN checks of varying depth, so this is most useful in bulk loads and in systems without them. For active status use the official portal service.
Common mistakes
Entering a lowercase letter, trailing spaces from Excel, or confusing the letter O with zero are the usual causes of failures. The function trims and uppercases input, but letter and digit confusion needs a human fix.
Frequently Asked Questions
What is the GSTIN format?
A GSTIN has 15 characters: 2 digit state code, the 10 character PAN, an entity number for that PAN in the state, the letter Z, and a checksum character.
Does a valid checksum mean the GSTIN is active?
No. It only proves the number is internally consistent. A cancelled or fake registration can still pass, so use the GST portal search for status.
Can I use the regex in Excel?
Newer Excel versions support regular expression functions, and older ones need VBA or Power Query. Python is simpler for bulk checks across thousands of rows.
Why does a real GSTIN fail?
Check for spaces, lowercase letters, the letter O versus zero, or a copy error. If none apply, compare the number with the registration certificate.
We can help you add data quality checks like this on top of your ERP master data, and keep them read-only until an accountant approves a fix.
Related Tools
India GST State Codes Reference
Two-digit GST state codes for every state and union territory, to check GSTINs and set place of supply in your ERP.
Developer ToolsTally XML Ledger Import Generator
Build the Import Data XML that creates a customer or supplier ledger in Tally Prime with GST details.
Country & TaxIndia GST Return Due Dates Reference
Searchable table of GST returns, who files them and the usual due date, for Indian manufacturers and accountants.
More Developer Tools tools
See all- ERP Item Master HSN and GST Rate Audit SQL Generator
- GSTR-1 HSN Summary Pandas Script Generator
- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton