Skip to content

Commit 8709ebe

Browse files
authored
Update README.md
1 parent 84119c0 commit 8709ebe

File tree

1 file changed

+83
-51
lines changed
  • Specialized Areas/Regular Expressions/Indian GSTIN Validator

1 file changed

+83
-51
lines changed

Specialized Areas/Regular Expressions/Indian GSTIN Validator/README.md

Lines changed: 83 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ This project provides a guide and resources for validating an Indian GST Identif
66

77
- [Features](#features)
88
- [GSTIN Format and Structure](#gstin-format-and-Structure)
9-
- [Validation Logic](#validation-logic)
9+
- [Validation Logic (Regular Expression)](#validation-logic)
1010
- [Examples](#examples)
11-
- [How to Run](#how-to-run)
1211
- [Contributing](#contributing)
13-
- [License](#license)
1412

1513
## Features
1614

@@ -20,79 +18,113 @@ This project provides a guide and resources for validating an Indian GST Identif
2018
## GSTIN Format and Structure
2119

2220
A valid GSTIN must be 15 characters long and adhere to the following structure:
21+
<table border="1">
22+
<thead>
23+
<tr>
24+
<th>Characters</th>
25+
<th>Length</th>
26+
<th>Description</th>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
<tr>
31+
<td>1-2</td>
32+
<td>2</td>
33+
<td><strong>State Code</strong> (Numeric, e.g., '27' for Maharashtra)</td>
34+
</tr>
35+
<tr>
36+
<td>3-12</td>
37+
<td>10</td>
38+
<td><strong>PAN Number</strong> of the taxpayer (first 5 alphabets, next 4 numbers, last 1 alphabet)</td>
39+
</tr>
40+
<tr>
41+
<td>13</td>
42+
<td>1</td>
43+
<td><strong>Entity Code</strong> (Registration count within the state, a number from 1-9 or an alphabet A-Z)</td>
44+
</tr>
45+
<tr>
46+
<td>14</td>
47+
<td>1</td>
48+
<td><strong>Default Character</strong> ('Z' by default)</td>
49+
</tr>
50+
<tr>
51+
<td>15</td>
52+
<td>1</td>
53+
<td><strong>Check Code/Digit</strong> (An alphabet or number for checksum)</td>
54+
</tr>
55+
</tbody>
56+
</table>
57+
58+
### Validation Logic (Regular Expression)
59+
60+
The most commonly used Regular Expression (Regex) pattern for GSTIN structural validation is:
2361

24-
### Function Signature
2562

2663
```javascript
27-
function isAlphanumeric(str)
64+
/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/
2865
```
2966

30-
### Parameters
67+
### Breakdown of the Regex:
3168

32-
- `str` (string): The string to be validated.
69+
- `^` : Matches the start of the string.
70+
- `[0-9]{2}` : Matches the first two digits for the State Code.
71+
- `[A-Z]{5}` : Matches the next five uppercase alphabets (part of the PAN).
72+
- `[0-9]{4}` : Matches the next four digits (part of the PAN).
73+
- `[A-Z]{1}` : Matches the next single uppercase alphabet (part of the PAN).
74+
- `[1-9A-Z]{1}` : Matches the 13th character (Entity Code) which is a number from 1-9 or an alphabet.
75+
- `Z` : Matches the 14th character exactly as 'Z'.
76+
- `[0-9A-Z]{1}` : Matches the 15th character (Check Code) which is a single number or uppercase alphabet.
77+
- `$` : Matches the end of the string.
3378

3479
### Returns
3580

36-
- `boolean`: `true` if the string is alphanumeric, `false` otherwise.
37-
38-
## Validation Logic
39-
40-
The validation is performed using a regular expression:
41-
42-
```javascript
43-
var alphanumericPattern = /^[a-zA-Z0-9]*$/;
44-
```
45-
46-
This pattern checks that the string contains only letters and numbers.
81+
- `boolean`: `true` if the string is matches with the given regular expression, `false` otherwise.
4782

4883
## Examples
4984

50-
Here are some example strings and their validation results:
85+
<table border="1">
86+
<thead>
87+
<tr>
88+
<th>GSTIN</th>
89+
<th>Status (Structural Regex)</th>
90+
</tr>
91+
</thead>
92+
<tbody>
93+
<tr>
94+
<td><code>33AAACH1645P2ZH</code></td>
95+
<td>Valid</td>
96+
</tr>
97+
<tr>
98+
<td><code>36AAICG1508J1ZN</code></td>
99+
<td>Valid (example structure)</td>
100+
</tr>
101+
<tr>
102+
<td><code>06BZAF67</code></td>
103+
<td>Invalid (wrong length)</td>
104+
</tr>
105+
<tr>
106+
<td><code>AZBZAHM6385P6Z2</code></td>
107+
<td>Invalid (State Code not numeric)</td>
108+
</tr>
109+
</tbody>
110+
</table>
51111

52-
```javascript
53-
var examples = [
54-
"abc123", // Valid
55-
"ABC", // Valid
56-
"123", // Valid
57-
"abc123!", // Invalid (contains '!')
58-
"hello world", // Invalid (contains space)
59-
"123-456", // Invalid (contains '-')
60-
];
61-
```
62112

63113
### Test Output
64114

65115
When running the provided examples, the output will be:
66116

67117
```
68-
abc123 is a valid alphanumeric string.
69-
ABC is a valid alphanumeric string.
70-
123 is a valid alphanumeric string.
71-
abc123! is NOT a valid alphanumeric string.
72-
hello world is NOT a valid alphanumeric string.
73-
123-456 is NOT a valid alphanumeric string.
118+
33AAACH1645P2ZH isValidGSTNo true
119+
36AAICG1508J1ZN isValidGSTNo true
120+
06BZAF67 isValidGSTNo false
121+
AZBZAHM6385P6Z2 isValidGSTNo false
74122
```
75123

76-
## How to Run
77-
78-
1. Clone this repository to your local machine:
79-
80-
```bash
81-
git clone https://github.com/yourusername/alphanumeric-validator.git
82-
```
83-
84-
2. Open your JavaScript environment (e.g., browser console, Node.js).
85-
86-
3. Copy and paste the code into the console or run it in your Node.js application.
87-
88124
## Contributing
89125

90126
Contributions are welcome! If you have suggestions or improvements, please create a pull request or open an issue.
91127

92-
## License
93-
94-
This project is licensed under the MIT License. See the LICENSE file for details.
95-
96128
---
97129

98130
Feel free to modify this README to fit your project's style or requirements!

0 commit comments

Comments
 (0)