validate
Validates a GSTIN.
Input normalisation applied before validation (in order):
Trim leading/trailing whitespace
Strip all internal whitespace (covers copy-paste with spaces)
Uppercase all characters
After normalisation, checks are applied in this order — first failing check wins:
InvalidReason.EMPTY if the result is blank
InvalidReason.WRONG_LENGTH if normalised length is not 15
InvalidReason.INVALID_FORMAT if the string does not match the GSTIN regex (
^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][0-9A-Z]Z[0-9A-Z]$)InvalidReason.INVALID_PREFIX if the 2-digit state code is not in the valid set (01–38)
InvalidReason.INVALID_CATEGORY if the 4th character of the embedded PAN (position 5 of GSTIN, 0-based) is not a valid PAN entity category (one of: P C H A B G J L F T)
InvalidReason.INVALID_CHECKSUM if the GSTN base-36 checksum fails
Never throws. Returns ValidationResult.Invalid for all invalid inputs.
Return
ValidationResult.Valid if the GSTIN passes all checks, ValidationResult.Invalid with an appropriate InvalidReason otherwise.
Parameters
Raw GSTIN string in any common input form.
Samples
check(GSTIN.validate("27AAPFU0939F1ZV") == ValidationResult.Valid)