From 00839e24b699355f513d83625b21b162ddfaf1c8 Mon Sep 17 00:00:00 2001 From: Viraj Hudlikar <31214018+vhudlikar@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:57:24 +0530 Subject: [PATCH 1/6] Create README.md This is readme file creation. --- .../Indian GSTIN Validator/README.md | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md 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..9437de71b1 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md @@ -0,0 +1,98 @@ +# Alphanumeric String Validator + +This project provides a simple JavaScript function to validate whether a given string is alphanumeric (i.e., contains only letters and numbers). + +## Table of Contents + +- [Features](#features) +- [Usage](#usage) +- [Validation Logic](#validation-logic) +- [Examples](#examples) +- [How to Run](#how-to-run) +- [Contributing](#contributing) +- [License](#license) + +## Features + +- Validates strings to ensure they contain only letters (a-z, A-Z) and numbers (0-9). +- Returns a boolean indicating the validity of the string. + +## Usage + +You can use the `isAlphanumeric` function to check if a string is alphanumeric. + +### Function Signature + +```javascript +function isAlphanumeric(str) +``` + +### Parameters + +- `str` (string): The string to be validated. + +### Returns + +- `boolean`: `true` if the string is alphanumeric, `false` otherwise. + +## Validation Logic + +The validation is performed using a regular expression: + +```javascript +var alphanumericPattern = /^[a-zA-Z0-9]*$/; +``` + +This pattern checks that the string contains only letters and numbers. + +## Examples + +Here are some example strings and their validation results: + +```javascript +var examples = [ + "abc123", // Valid + "ABC", // Valid + "123", // Valid + "abc123!", // Invalid (contains '!') + "hello world", // Invalid (contains space) + "123-456", // Invalid (contains '-') +]; +``` + +### Test Output + +When running the provided examples, the output will be: + +``` +abc123 is a valid alphanumeric string. +ABC is a valid alphanumeric string. +123 is a valid alphanumeric string. +abc123! is NOT a valid alphanumeric string. +hello world is NOT a valid alphanumeric string. +123-456 is NOT a valid alphanumeric string. +``` + +## How to Run + +1. Clone this repository to your local machine: + + ```bash + git clone https://github.com/yourusername/alphanumeric-validator.git + ``` + +2. Open your JavaScript environment (e.g., browser console, Node.js). + +3. Copy and paste the code into the console or run it in your Node.js application. + +## Contributing + +Contributions are welcome! If you have suggestions or improvements, please create a pull request or open an issue. + +## License + +This project is licensed under the MIT License. See the LICENSE file for details. + +--- + +Feel free to modify this README to fit your project's style or requirements! From ac77e3a7342a1a19ea1123d5ba6c33a4970a83b9 Mon Sep 17 00:00:00 2001 From: Viraj Hudlikar <31214018+vhudlikar@users.noreply.github.com> Date: Sat, 4 Oct 2025 00:00:31 +0530 Subject: [PATCH 2/6] Create IndianGSTINValidator.js This is js file of code --- .../IndianGSTINValidator.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js 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..a45a4234b6 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js @@ -0,0 +1,37 @@ +// Alphanumeric regex pattern +var alphanumericPattern = /^[a-zA-Z0-9]*$/; + +// Function to validate if a string is alphanumeric +function isAlphanumeric(str) { + return alphanumericPattern.test(str); +} + +// Example usage +var examples = [ + "abc123", // Valid + "ABC", // Valid + "123", // Valid + "abc123!", // Invalid (contains '!') + "hello world", // Invalid (contains space) + "123-456", // Invalid (contains '-') +]; + +// Test the examples using a for loop +for (var i = 0; i < examples.length; i++) { + var example = examples[i]; + if (isAlphanumeric(example)) { + gs.print(example+" is a valid alphanumeric string."); + } else { + gs.print(example+ " is NOT a valid alphanumeric string."); + } +} + +/* +when you run this code, it will output: +*** Script: abc123 is a valid alphanumeric string. +*** Script: ABC is a valid alphanumeric string. +*** Script: 123 is a valid alphanumeric string. +*** Script: abc123! is NOT a valid alphanumeric string. +*** Script: hello world is NOT a valid alphanumeric string. +*** Script: 123-456 is NOT a valid alphanumeric string. +*/ From 84119c06d3b8a1dfd9990db282e7598e873833f7 Mon Sep 17 00:00:00 2001 From: Viraj Hudlikar <31214018+vhudlikar@users.noreply.github.com> Date: Sat, 4 Oct 2025 00:13:32 +0530 Subject: [PATCH 3/6] Update README.md --- .../Indian GSTIN Validator/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md index 9437de71b1..48ca94cff3 100644 --- a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md +++ b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md @@ -1,11 +1,11 @@ -# Alphanumeric String Validator +# Indian GSTIN Validator -This project provides a simple JavaScript function to validate whether a given string is alphanumeric (i.e., contains only letters and numbers). +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) -- [Usage](#usage) +- [GSTIN Format and Structure](#gstin-format-and-Structure) - [Validation Logic](#validation-logic) - [Examples](#examples) - [How to Run](#how-to-run) @@ -14,12 +14,12 @@ This project provides a simple JavaScript function to validate whether a given s ## Features -- Validates strings to ensure they contain only letters (a-z, A-Z) and numbers (0-9). -- Returns a boolean indicating the validity of the string. +- Defines the regular expression pattern for a structurally valid GSTIN. +- Explains the 15-character structure of the GSTIN. -## Usage +## GSTIN Format and Structure -You can use the `isAlphanumeric` function to check if a string is alphanumeric. +A valid GSTIN must be 15 characters long and adhere to the following structure: ### Function Signature From 8709ebee725144078d2ae7867a149467959a2edb Mon Sep 17 00:00:00 2001 From: Viraj Hudlikar <31214018+vhudlikar@users.noreply.github.com> Date: Sat, 4 Oct 2025 00:50:30 +0530 Subject: [PATCH 4/6] Update README.md --- .../Indian GSTIN Validator/README.md | 134 +++++++++++------- 1 file changed, 83 insertions(+), 51 deletions(-) diff --git a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md index 48ca94cff3..38ff656fad 100644 --- a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md +++ b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md @@ -6,11 +6,9 @@ This project provides a guide and resources for validating an Indian GST Identif - [Features](#features) - [GSTIN Format and Structure](#gstin-format-and-Structure) -- [Validation Logic](#validation-logic) +- [Validation Logic (Regular Expression)](#validation-logic) - [Examples](#examples) -- [How to Run](#how-to-run) - [Contributing](#contributing) -- [License](#license) ## Features @@ -20,79 +18,113 @@ This project provides a guide and resources for validating an Indian GST Identif ## 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: -### Function Signature ```javascript -function isAlphanumeric(str) +/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/ ``` -### Parameters +### Breakdown of the Regex: -- `str` (string): The string to be validated. +- `^` : 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 alphanumeric, `false` otherwise. - -## Validation Logic - -The validation is performed using a regular expression: - -```javascript -var alphanumericPattern = /^[a-zA-Z0-9]*$/; -``` - -This pattern checks that the string contains only letters and numbers. +- `boolean`: `true` if the string is matches with the given regular expression, `false` otherwise. ## Examples -Here are some example strings and their validation results: + + + + + + + + + + + + + + + + + + + + + + + + + +
GSTINStatus (Structural Regex)
33AAACH1645P2ZHValid
36AAICG1508J1ZNValid (example structure)
06BZAF67Invalid (wrong length)
AZBZAHM6385P6Z2Invalid (State Code not numeric)
-```javascript -var examples = [ - "abc123", // Valid - "ABC", // Valid - "123", // Valid - "abc123!", // Invalid (contains '!') - "hello world", // Invalid (contains space) - "123-456", // Invalid (contains '-') -]; -``` ### Test Output When running the provided examples, the output will be: ``` -abc123 is a valid alphanumeric string. -ABC is a valid alphanumeric string. -123 is a valid alphanumeric string. -abc123! is NOT a valid alphanumeric string. -hello world is NOT a valid alphanumeric string. -123-456 is NOT a valid alphanumeric string. +33AAACH1645P2ZH isValidGSTNo true +36AAICG1508J1ZN isValidGSTNo true +06BZAF67 isValidGSTNo false +AZBZAHM6385P6Z2 isValidGSTNo false ``` -## How to Run - -1. Clone this repository to your local machine: - - ```bash - git clone https://github.com/yourusername/alphanumeric-validator.git - ``` - -2. Open your JavaScript environment (e.g., browser console, Node.js). - -3. Copy and paste the code into the console or run it in your Node.js application. - ## Contributing Contributions are welcome! If you have suggestions or improvements, please create a pull request or open an issue. -## License - -This project is licensed under the MIT License. See the LICENSE file for details. - --- Feel free to modify this README to fit your project's style or requirements! From 256fe927e7d450c4a48a1788e6d4e982034e317a Mon Sep 17 00:00:00 2001 From: Viraj Hudlikar <31214018+vhudlikar@users.noreply.github.com> Date: Sat, 4 Oct 2025 00:52:46 +0530 Subject: [PATCH 5/6] Update README.md --- .../Regular Expressions/Indian GSTIN Validator/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md index 38ff656fad..f88e19a8eb 100644 --- a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md +++ b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md @@ -80,7 +80,7 @@ The most commonly used Regular Expression (Regex) pattern for GSTIN structural v - `boolean`: `true` if the string is matches with the given regular expression, `false` otherwise. -## Examples +### Examples From 08a76ad785e42d7b2596e5f301a0b86546aa2e33 Mon Sep 17 00:00:00 2001 From: Viraj Hudlikar <31214018+vhudlikar@users.noreply.github.com> Date: Sat, 4 Oct 2025 00:56:53 +0530 Subject: [PATCH 6/6] Update IndianGSTINValidator.js --- .../IndianGSTINValidator.js | 71 +++++++++++-------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js index a45a4234b6..5975f7593c 100644 --- a/Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js +++ b/Specialized Areas/Regular Expressions/Indian GSTIN Validator/IndianGSTINValidator.js @@ -1,37 +1,48 @@ -// Alphanumeric regex pattern -var alphanumericPattern = /^[a-zA-Z0-9]*$/; -// Function to validate if a string is alphanumeric -function isAlphanumeric(str) { - return alphanumericPattern.test(str); -} +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"; + } -// Example usage -var examples = [ - "abc123", // Valid - "ABC", // Valid - "123", // Valid - "abc123!", // Invalid (contains '!') - "hello world", // Invalid (contains space) - "123-456", // Invalid (contains '-') -]; - -// Test the examples using a for loop -for (var i = 0; i < examples.length; i++) { - var example = examples[i]; - if (isAlphanumeric(example)) { - gs.print(example+" is a valid alphanumeric string."); - } else { - gs.print(example+ " is NOT a valid alphanumeric string."); + // 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: abc123 is a valid alphanumeric string. -*** Script: ABC is a valid alphanumeric string. -*** Script: 123 is a valid alphanumeric string. -*** Script: abc123! is NOT a valid alphanumeric string. -*** Script: hello world is NOT a valid alphanumeric string. -*** Script: 123-456 is NOT a valid alphanumeric string. +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 */