Every GST invoice in India carries a 15-character GSTIN, and a typo in it silently breaks the buyer's input tax credit. A regex alone catches the shape but not a mistyped digit. The 15th character is a check character, so you can catch most typos offline before the bill is saved.
Structure
Position Meaning Example (27AAPFU0939F1ZV)
1-2 State code 27 (Maharashtra)
3-12 PAN of the business AAPFU0939F
13 Entity number for the same PAN 1
14 Default "Z" Z
15 Check character V
The checksum
The check character uses a base-36 alphabet ( 0-9A-Z ). Walk the first 14 characters, multiply each value by 1 or 2 alternately, add the base-36 "digits" of each product, and the check character is whatever brings the total to a multiple of 36.
using System . Text . RegularExpressions ;
public static class Gstin { private const string Charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; private static readonly Regex Shape = new ( @ "^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$" , RegexOptions .…