Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for GST Identification Number (GSTIN)

Tags:

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

  • List itemThe first two digits of this number will represent the state code as per Indian Census 2011
  • The next ten digits will be the PAN number of the taxpayer
  • The thirteenth digit will be assigned based on the number of registration within a state
  • The fourteenth digit will be Z by default
  • The last digit will be for check code
like image 569
Minkesh Jain Avatar asked Jun 08 '17 09:06

Minkesh Jain


People also ask

How do I validate a GST number in Python?

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.

How do I validate a GST number in Excel?

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.


2 Answers

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} 

enter image description here

Format details

  1. First 2 digits of the GST Number will represent State Code as per the Census (2011).
  2. Next 10 digits will be same as in the PAN number of the taxpayer.
    • First five will be alphabets
    • Next four will be numbers
    • Last will be check code
  3. The 13th digit will be the number of registration you take within a state i.e. after 9, A to Z is considered as 10 to 35 .
  4. 14th digit will be Z by default.
  5. Last would be the check code.

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

like image 132
tk120404 Avatar answered Oct 17 '22 10:10

tk120404


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.

like image 44
Mitchell Anicas Avatar answered Oct 17 '22 10:10

Mitchell Anicas