Skip to content

Commit 42111ab

Browse files
committed
Revert "add function to validate GST number"
This reverts commit cd1f6fe.
1 parent cd1f6fe commit 42111ab

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

lib/src/rendering.dart

+12-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
part of gstvalidator;
22

3+
34
class GSTvalidator extends StatefulWidget {
45
final String labelText;
56

@@ -36,8 +37,15 @@ class _GSTvalidatorState extends State<GSTvalidator> {
3637
autovalidateMode: widget.autovalidateMode,
3738
keyboardType: widget.keyboardType,
3839
validator: ((value) {
39-
String res = validateGstinCheckDigit(widget.controller.text);
40-
return res.isEmpty ? null : res;
40+
final RegExp pattern = RegExp(
41+
r"^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$");
42+
if (value == null || value.isEmpty) {
43+
return '! Please enter value';
44+
}
45+
if (!pattern.hasMatch(value)) {
46+
return '! Invalid GST format';
47+
}
48+
return null;
4149
}),
4250
maxLength: widget.maxLength,
4351
onChanged: (text) {
@@ -68,35 +76,9 @@ class _GSTvalidatorState extends State<GSTvalidator> {
6876
return 'Please enter a value';
6977
}
7078
if (!pattern.hasMatch(value)) {
71-
return 'Invalid GST format';
79+
return 'Invalid input format';
7280
}
7381
return null;
7482
}
75-
76-
String validateGstinCheckDigit(String gstin) {
77-
var gstval = _validateInput(gstin);
78-
if ((gstval ?? '').toString().isNotEmpty) {
79-
return gstval.toString();
80-
}
81-
int factor = 1;
82-
int total = 0;
83-
String codePointChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
84-
int mod = codePointChars.length;
85-
String inputChars = gstin.substring(0, gstin.length - 1);
86-
87-
for (int i = 0; i < inputChars.length; i++) {
88-
String char = inputChars[i];
89-
int digit = factor * codePointChars.indexOf(char);
90-
digit = (digit ~/ mod) + (digit % mod);
91-
total += digit;
92-
factor = (factor == 1) ? 2 : 1;
93-
}
94-
95-
if (gstin[gstin.length - 1] !=
96-
codePointChars[((mod - (total % mod)) % mod)]) {
97-
return "The GSTIN provided is not valid; \n It fails the check digit validation.";
98-
}
99-
100-
return "";
101-
}
10283
}
84+

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: gstvalidator
22
description: "A Flutter package for validating GST (Goods and Services Tax) numbers."
3-
version: 0.0.6
3+
version: 0.0.5
44
homepage:
55

66
environment:

0 commit comments

Comments
 (0)