diff --git a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js new file mode 100644 index 0000000000..5975f7593c --- /dev/null +++ b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js @@ -0,0 +1,48 @@ + +function isValidGSTNo(str) { + // Regex to check valid GST CODE + var regex = /^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/; + + // GST CODE is empty return false + if (str == null) { + return "false"; + } + + // Return true if the GST_CODE matched the ReGex + if (regex.test(str) == true) { + return "true"; + } + else { + return "false"; + } +} + +// Test Case 1: +var str1 = "33AAACH1645P2ZH"; +gs.print(str1 +' isValidGSTNo '+isValidGSTNo(str1)); + +// Test Case 2: +var str2 = "06BZAF67"; +gs.print(str2 +' isValidGSTNo '+isValidGSTNo(str2)); + +// Test Case 3: +var str3 = "AZBZAHM6385P6Z2"; +gs.print(str3 +' isValidGSTNo '+isValidGSTNo(str3)); + +// Test Case 4: +var str4 = "36AAICG1508J1ZN"; +gs.print(str4 +' isValidGSTNo '+isValidGSTNo(str4)); + +// Test Case 5: +var str5 = "27AAUCS0795B1Z0"; +gs.print(str5 +' isValidGSTNo '+isValidGSTNo(str5)); + + +/* +When you run this code, it will output: +*** Script: 33AAACH1645P2ZH isValidGSTNo true +*** Script: 06BZAF67 isValidGSTNo false +*** Script: AZBZAHM6385P6Z2 isValidGSTNo false +*** Script: 36AAICG1508J1ZN isValidGSTNo true +*** Script: 27AAUCS0795B1Z0 isValidGSTNo true +*/ diff --git a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md new file mode 100644 index 0000000000..f88e19a8eb --- /dev/null +++ b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md @@ -0,0 +1,130 @@ +# Indian GSTIN Validator + +This project provides a guide and resources for validating an Indian GST Identification Number (GSTIN) using a Regular Expression. A GSTIN is a 15-character alphanumeric code assigned to taxpayers in India. + +## Table of Contents + +- [Features](#features) +- [GSTIN Format and Structure](#gstin-format-and-Structure) +- [Validation Logic (Regular Expression)](#validation-logic) +- [Examples](#examples) +- [Contributing](#contributing) + +## Features + +- Defines the regular expression pattern for a structurally valid GSTIN. +- Explains the 15-character structure of the GSTIN. + +## GSTIN Format and Structure + +A valid GSTIN must be 15 characters long and adhere to the following structure: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CharactersLengthDescription
1-22State Code (Numeric, e.g., '27' for Maharashtra)
3-1210PAN Number of the taxpayer (first 5 alphabets, next 4 numbers, last 1 alphabet)
131Entity Code (Registration count within the state, a number from 1-9 or an alphabet A-Z)
141Default Character ('Z' by default)
151Check Code/Digit (An alphabet or number for checksum)
+ +### Validation Logic (Regular Expression) + +The most commonly used Regular Expression (Regex) pattern for GSTIN structural validation is: + + +```javascript +/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/ +``` + +### Breakdown of the Regex: + +- `^` : Matches the start of the string. +- `[0-9]{2}` : Matches the first two digits for the State Code. +- `[A-Z]{5}` : Matches the next five uppercase alphabets (part of the PAN). +- `[0-9]{4}` : Matches the next four digits (part of the PAN). +- `[A-Z]{1}` : Matches the next single uppercase alphabet (part of the PAN). +- `[1-9A-Z]{1}` : Matches the 13th character (Entity Code) which is a number from 1-9 or an alphabet. +- `Z` : Matches the 14th character exactly as 'Z'. +- `[0-9A-Z]{1}` : Matches the 15th character (Check Code) which is a single number or uppercase alphabet. +- `$` : Matches the end of the string. + +### Returns + +- `boolean`: `true` if the string is matches with the given regular expression, `false` otherwise. + +### Examples + + + + + + + + + + + + + + + + + + + + + + + + + + +
GSTINStatus (Structural Regex)
33AAACH1645P2ZHValid
36AAICG1508J1ZNValid (example structure)
06BZAF67Invalid (wrong length)
AZBZAHM6385P6Z2Invalid (State Code not numeric)
+ + +### Test Output + +When running the provided examples, the output will be: + +``` +33AAACH1645P2ZH isValidGSTNo true +36AAICG1508J1ZN isValidGSTNo true +06BZAF67 isValidGSTNo false +AZBZAHM6385P6Z2 isValidGSTNo false +``` + +## Contributing + +Contributions are welcome! If you have suggestions or improvements, please create a pull request or open an issue. + +--- + +Feel free to modify this README to fit your project's style or requirements!