[英]Regex for GST Identification Number (GSTIN)
What is the regex for the GST number in India.印度 GST 编号的正则表达式是什么。 You can read more about the GST numbers from https://cleartax.in/s/know-your-gstin On a summary level the number is represented as您可以从https://cleartax.in/s/know-your-gstin阅读更多有关 GST 数字的信息 在摘要级别,该数字表示为
Here is the regex and checksum validation for GSTIN这是 GSTIN 的正则表达式和校验和验证
\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}
Format details格式详情
Here is the code for verifying/validating the gstin number using the checksum in js这是使用js中的校验和验证/验证gstin编号的代码
function checksum(g){ let regTest = /\\d{2}[AZ]{5}\\d{4}[AZ]{1}[AZ\\d]{1}[Z]{1}[AZ\\d]{1}/.test(g) if(regTest){ let a=65,b=55,c=36; return Array['from'](g).reduce((i,j,k,g)=>{ p=(p=(j.charCodeAt(0)<a?parseInt(j):j.charCodeAt(0)-b)*(k%2+1))>c?1+(pc):p; return k<14?i+p:j==((c=(c-(i%c)))<10?c:String.fromCharCode(c+b)); },0); } return regTest } console.log(checksum('27AAPFU0939F1ZV')) console.log(checksum('27AASCS2460H1Z0')) console.log(checksum('29AAGCB7383J1Z4'))
GST regex and checksum in various programming languages各种编程语言中的 GST 正则表达式和校验和
Here is the regex that I came up with:这是我想出的正则表达式:
/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/
According to H&R Block India GSTIN guide , the 13th 'digit' (entity code) is "an alpha-numeric number (first 1-9 and then AZ)".根据H&R Block India GSTIN 指南,第 13 个“数字”(实体代码)是“一个字母数字数字(前 1-9,然后是 AZ)”。 That is, zero is not allowed and AZ represent 10-35.也就是说,不允许为零,AZ 代表 10-35。 Hence the [1-9A-Z]
is more accurate than [0-9]
.因此[1-9A-Z]
比[0-9]
更准确。
The last digit, "check digit", is indeed alphanumeric: [0-9A-Z]
.最后一个数字,“校验位”,确实是字母数字: [0-9A-Z]
。 I have independently confirmed by obtaining and testing actual GSTINs.我已通过获取和测试实际 GSTIN 独立确认。
The correct validation for GSTIN should be GSTIN 的正确验证应该是
^([0][1-9]|[1-2][0-9]|[3][0-7])([a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9a-zA-Z]{1}[zZ]{1}[0-9a-zA-Z]{1})+$
The first 2 digits denote the State Code (01-37) as defined in the Code List for Land Regions.前 2 位数字表示州代码 (01-37),如土地区域代码列表中所定义。
The next 10 characters pertain to PAN Number in AAAAA9999X format.接下来的 10 个字符与 AAAAA9999X 格式的 PAN 编号有关。
13th character indicates the number of registrations an entity has within a state for the same PAN.第 13 个字符表示实体在同一 PAN 的状态内的注册数量。
14th character is currently defaulted to "Z"第 14 个字符当前默认为“Z”
15th character is a checksum digit第 15 个字符是校验和数字
This regex pattern accommodates lower and upper case.此正则表达式模式适用于小写和大写。
To add to above answers, this answer also provides code snippet for checksum digit要添加到上述答案,此答案还提供了校验和数字的代码片段
public static final String GSTINFORMAT_REGEX = "[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}";
public static final String GSTN_CODEPOINT_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static String getGSTINWithCheckDigit(String gstinWOCheckDigit) throws Exception {
int factor = 2;
int sum = 0;
int checkCodePoint = 0;
char[] cpChars;
char[] inputChars;
try {
if (gstinWOCheckDigit == null) {
throw new Exception("GSTIN supplied for checkdigit calculation is null");
}
cpChars = GSTN_CODEPOINT_CHARS.toCharArray();
inputChars = gstinWOCheckDigit.trim().toUpperCase().toCharArray();
int mod = cpChars.length;
for (int i = inputChars.length - 1; i >= 0; i--) {
int codePoint = -1;
for (int j = 0; j < cpChars.length; j++) {
if (cpChars[j] == inputChars[i]) {
codePoint = j;
}
}
int digit = factor * codePoint;
factor = (factor == 2) ? 1 : 2;
digit = (digit / mod) + (digit % mod);
sum += digit;
}
checkCodePoint = (mod - (sum % mod)) % mod;
return gstinWOCheckDigit + cpChars[checkCodePoint];
} finally {
inputChars = null;
cpChars = null;
}
}
Source: GST Google Group Link , Code Snippet Link来源: GST 谷歌群组链接, 代码片段链接
I Used This One And Checked It Against 30+ GSTIN and it worked flawless.我使用了这个并根据30+ GSTIN检查了它,它完美无缺。
/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/
The Last Check Digit Also Seems to be alphanumeric in some of the GSTIN i came across.在我遇到的一些 GSTIN 中,最后一个校验位似乎也是字母数字。
Try this.试试这个。 It is working as per GSTIN.它按照 GSTIN 工作。
^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$
The correct regex
for GSTIN
is as under- GSTIN
的正确regex
如下-
^([0][1-9]|[1-2][0-9]|[3][0-7])([A-Z]{5})([0-9]{4})([A-Z]{1}[1-9A-Z]{1})([Z]{1})([0-9A-Z]{1})+$
The above one is correct which have been applied to more than 300 valid taxpayers whom you can validate from this link以上是正确的,已应用于300多个有效纳税人,您可以从此链接验证
Try this one with jQuery用 jQuery 试试这个
$(document).ready(function() { $.validator.addMethod("gst", function(value3, element3) { var gst_value = value3.toUpperCase(); var reg = /^([0-9]{2}[a-zA-Z]{4}([a-zA-Z]{1}|[0-9]{1})[0-9]{4}[a-zA-Z]{1}([a-zA-Z]|[0-9]){3}){0,15}$/; if (this.optional(element3)) { return true; } if (gst_value.match(reg)) { return true; } else { return false; } }, "Please specify a valid GSTTIN Number"); $('#myform').validate({ // initialize the plugin rules: { gst: { required: true, gst: true } }, submitHandler: function(form) { alert('valid form submitted'); return false; } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script> <form id="myform" action="" method="post"> <div> <label>GSTTIN #</label> <div> <input type="text" name="gst" value="" id="input-gst" /> </div> </div> <button type="submit">Register</button> </form>
正则表达式应该是:
/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[0-9]{1}Z[0-9]{1}$/
Correct Regex Could be:正确的正则表达式可能是:
/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[0-9]{1}Z[0-9]{1}?$/
It Works for me.这个对我有用。
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
ValidationExpression="[0-9]{2}[(a-z)(A-Z)]{5}\d{4}[(a-z)(A-Z)]{1}\d{1}Z\d{1}"
SetFocusOnError="true"
ControlToValidate="txtGST"
Display="Dynamic"
runat="server"
ErrorMessage="Invalid GST No."
ValidationGroup="Add"
ForeColor="Red"></asp:RegularExpressionValidator>
正确的 GSTIN 验证将涵盖印度的 27 个州,
^([0][1-9]|[1-2][0-9]|[3][0-7])([a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9a-zA-Z]{1}[zZ]{1}[0-9a-zA-Z]{1})+$
If you want a node library, you can use https://npmjs.org/gstin-validator如果你想要一个节点库,你可以使用https://npmjs.org/gstin-validator
var validator = require('gstin-validator');
validator.isValidGSTNumber('12AAACI1681G1Z0'); //returns boolean value.
validator.ValidateGSTIN('47AAACI1681G1Z0'); // returns a response string with Error message
validator.getGSTINInfo('12AAACI1681G1Z0'); // returns metadata for GSTIN based on numbering scheme followed
This is general compact regex that you can use in your code : ^\\d{2}\\D{5}\\d{4}\\D\\dZ\\w这是您可以在代码中使用的通用紧凑正则表达式: ^\\d{2}\\D{5}\\d{4}\\D\\dZ\\w
Swift 4 code for GSTIN validation as below :用于 GSTIN 验证的 Swift 4 代码如下:
class func isValidGSTIN(_ gstin : String)-> Bool {
let gstinRegex = "^\\d{2}\\D{5}\\d{4}\\D\\dZ\\w"
let test = NSPredicate(format: "SELF MATCHES %@", gstinRegex)
return test.evaluate(with: gstin.uppercased())
}
IF you using yup try below code working for me如果您使用 yup 尝试以下代码为我工作
gst_no:Yup.string()
.trim()
.matches(/[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}[1-9A-Z]{1}$/ , 'Is not in correct format')
.required(),
input : 21LKJLK1235M22输入:21LKJLK1235M22
demo :演示:
<form action="#" onSubmit="return false">
<input type="text" id="gstin" onChange="testGSTIN(this);">
</form>
<p id="out"></p>
<script>
var re = /^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/;
function testGSTIN(gstinInput) {
var OK = re.exec(gstinInput.value);
var out = document.querySelector('#out');
if (!OK) {
out.textContent = `${gstinInput.value} isn't a gstin number not correct`;
} else {
out.textContent = `GSTIN is correct ${OK[0]}`;
}
}
//live demo https://jsfiddle.net/rokrd/L2o1bu6q/5/
</script>
The GST validation using Regex should be like this below:使用 Regex 的 GST 验证应如下所示:
let gstTest = /\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}/
if (gstin_number) {
message = !gstTest.test(gstin_number)
? 'The GST Number is not a valid'
: '';
}
My working regex is我的工作正则表达式是
/^([0][1-9]|[1-2][0-9]|[3][0-8])[A-Z]{3}[ABCFGHLJPTF]{1}[A-Z]{1}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}/
according to 38 States as on yr.根据 38 个州,截至去年。 2021. 2021。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.