Skip to content

Commit ac77e3a

Browse files
authored
Create IndianGSTINValidator.js
This is js file of code
1 parent 00839e2 commit ac77e3a

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Alphanumeric regex pattern
2+
var alphanumericPattern = /^[a-zA-Z0-9]*$/;
3+
4+
// Function to validate if a string is alphanumeric
5+
function isAlphanumeric(str) {
6+
return alphanumericPattern.test(str);
7+
}
8+
9+
// Example usage
10+
var examples = [
11+
"abc123", // Valid
12+
"ABC", // Valid
13+
"123", // Valid
14+
"abc123!", // Invalid (contains '!')
15+
"hello world", // Invalid (contains space)
16+
"123-456", // Invalid (contains '-')
17+
];
18+
19+
// Test the examples using a for loop
20+
for (var i = 0; i < examples.length; i++) {
21+
var example = examples[i];
22+
if (isAlphanumeric(example)) {
23+
gs.print(example+" is a valid alphanumeric string.");
24+
} else {
25+
gs.print(example+ " is NOT a valid alphanumeric string.");
26+
}
27+
}
28+
29+
/*
30+
when you run this code, it will output:
31+
*** Script: abc123 is a valid alphanumeric string.
32+
*** Script: ABC is a valid alphanumeric string.
33+
*** Script: 123 is a valid alphanumeric string.
34+
*** Script: abc123! is NOT a valid alphanumeric string.
35+
*** Script: hello world is NOT a valid alphanumeric string.
36+
*** Script: 123-456 is NOT a valid alphanumeric string.
37+
*/

0 commit comments

Comments
 (0)