GST标识号(GSTIN)的正则表达式

Min*_*ain 13 javascript regex

印度商品及服务税号码的正则表达是什么?您可以从https://cleartax.in/s/know-your-gstin了解有关GST数字的更多信息.在 摘要级别,数字表示为

  • 列表项此数字的前两位数字代表根据2011年印度人口普查的州代码
  • 接下来的十位数字将是纳税人的PAN号码
  • 将根据州内的登记数量分配第十三位
  • 默认情况下,第十四位为Z.
  • 最后一位数字用于检查代码

tk1*_*404 31

这是GSTIN的正则表达式和校验和验证

\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

格式细节

  1. 根据人口普查(2011年),商品及服务税编号的前2位数代表国家代码.
  2. 接下来的10位数字将与纳税人的PAN号码相同.
    • 前五个将是字母表
    • 接下来的四个将是数字
    • 最后将是检查代码
  3. 第13位是您在一个州内注册的数量,即在9之后,A到Z被认为是10到35.
  4. 默认情况下,第14位为Z.
  5. 最后一个是检查代码.

以下是使用js中的校验和验证/验证gstin编号的代码

function checksum(g){
    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+(p-c):p;
    return k<14?i+p:j==((c=(c-(i%c)))<10?c:String.fromCharCode(c+b));
    },0);     
}

console.log(checksum('27AAPFU0939F1ZV'))
console.log(checksum('27AASCS2460H1Z0'))
console.log(checksum('29AAGCB7383J1Z4'))
Run Code Online (Sandbox Code Playgroud)

各种编程语言中的GST正则表达式和校验和


小智 14

这是我想出的正则表达式:

/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/
Run Code Online (Sandbox Code Playgroud)

根据H&R Block India GSTIN指南,第13个"数字"(实体代码)是"字母数字(首先是1-9,然后是AZ)".也就是说,不允许为零,AZ代表10-35.因此[1-9A-Z]更准确[0-9].

最后一位数字"校验位"确实是字母数字:[0-9A-Z].通过获取和测试实际GSTIN,我已经独立确认.


jef*_*man 7

GSTIN的正确验证应该是

^([0][1-9]|[1-2][0-9]|[3][0-5])([a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9a-zA-Z]{1}[zZ]{1}[0-9a-zA-Z]{1})+$
Run Code Online (Sandbox Code Playgroud)

前两位数字表示土地区域代码清单(2011年印度人口普查 - 链接)中定义的国家代码(01-35 )

接下来的10个字符与AAAAA9999X格式的PAN编号有关.

第13个字符表示实体在同一PAN的状态下的注册数.

第14个字符目前默认为"Z"

第15个字符是校验和数字

这种正则表达式适用于大写和小写.


Vir*_*ain 6

为了添加到前面的答案,此答案还提供了校验和数字的代码片段。

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

资料来源:


Min*_*ain 1

正则表达式应该是:

/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[0-9]{1}Z[0-9]{1}$/
Run Code Online (Sandbox Code Playgroud)