Skip to content

Instantly share code, notes, and snippets.

@surajitbasak109
Last active March 26, 2021 08:16
Show Gist options
  • Save surajitbasak109/befcff428e8e3f3c4ed138d561275454 to your computer and use it in GitHub Desktop.
Save surajitbasak109/befcff428e8e3f3c4ed138d561275454 to your computer and use it in GitHub Desktop.
GST Format Validation

GSTIN Format

GSTIN Format

Format Explaination:

The GST number is a 15-digit number, which is unique for each taxpayer.

  • The first two digits represent the state code. Each state in India is assigned a unique state code.
  • The next ten digits of the GST number contain the PAN of the taxpayer.
  • The next two digits of the GST number represent the entity code. It represents the number of registrations that were made by a business entity within a state.
  • The last digit serves as a check code. It is used to detect errors.

Regex Structure:

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.
  • [A-Z]{5} represents the next five characters should be any upper case alphabets.
  • [0-9]{4} represents the next four characters should be any number.
  • [A-Z]{1} represents the next character should be any upper case alphabet.
  • [1-9A-Z]{1} represents the 13th character should be a number from 1-9 or an alphabet.
  • Z represents the 14th character should be Z.
  • [0-9A-Z]{1} represents the 15th character should be an alphabet or a number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment