What is the regex for the GST number in India. You can read more about the GST numbers from https://cleartax.in/s/know-your-gstin On a summary level the number is represented as
regex = “^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$”; Where: ^ represents the starting of the string. [0-9]{2} represents the first two characters should be a number.
Using the tool is super easy. It is just an Excel Formula. Copy paste your data in excel file (Download Link Above) & use the formula = AdarshGSTINCheck(A1). That's it.
Here is the regex and checksum validation for GSTIN
\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}
Format details
Here is the code for verifying/validating the gstin number using the checksum in js
function checksum(g){ let regTest = /\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}/.test(g) if(regTest){ let a=65,b=55,c=36; return Array['from'](g).reduce((i,j,k,g)=>{ p=(p=(j.charCodeAt(0)<a?parseInt(j):j.charCodeAt(0)-b)*(k%2+1))>c?1+(p-c):p; return k<14?i+p:j==((c=(c-(i%c)))<10?c:String.fromCharCode(c+b)); },0); } return regTest } console.log(checksum('27AAPFU0939F1ZV')) console.log(checksum('27AASCS2460H1Z0')) console.log(checksum('29AAGCB7383J1Z4'))
GST regex and checksum in various programming languages
Here is the regex that I came up with:
/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/
According to H&R Block India GSTIN guide, the 13th 'digit' (entity code) is "an alpha-numeric number (first 1-9 and then A-Z)". That is, zero is not allowed and A-Z represent 10-35. Hence the [1-9A-Z]
is more accurate than [0-9]
.
The last digit, "check digit", is indeed alphanumeric: [0-9A-Z]
. I have independently confirmed by obtaining and testing actual GSTINs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With