将GSTIN编号与PAN编号

时间:2017-06-26 06:40:00

标签: javascript jquery

我有两个数字GSTIN和PAN

我想匹配GSTIN号码从3到12开始,它将等于PAN号码。

如果匹配

,它应该生成警报

例如

My PAN is : 1234567891

My GSTIN is : aa1234567891bbb

然后是正确的

但是

My PAN is : 1234567891

My GSTIN is : aa7894561239bbb

然后是错误的

我在谷歌搜索但无法找到任何解决方案,这可能吗?请指导我正确的方向。

enter image description here

我尝试使用substr下面的代码,但我无法获得该值



var pan = document.getElementById("pan");
var unino = document.getElementById("gstin");

var res = unino.substr(2, 11);

document.getElementById("button").addEventListener("click", function() {
    alert( pan.value+'&'+res.value );
});

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />

<!DOCTYPE html>
<html>
<head>
  <title>Test</title>
</head>
<style type="text/css">

</style>
<body>
<div class="container">
<form method="post">
<div class="form-group">
	<label>PAN</label>
	<div class="input-group">
  <input pattern=".{10,10}" maxlength="10" required="" type="text" class="form-control" name="pan" id="pan"  placeholder="PAN No 10 digist" value="" title="PAN Number must be 10 character"/>
	</div>
</div>

<div class="form-group">
  <label>gstin</label>
  <div class="input-group">
  <input required="" type="text" class="form-control" name="gstin" id="gstin"  placeholder="gstin" value=""/>
  </div>
</div>

<input type="submit" name="submit" value="submit" class="btn btn-primary" id="button">
</form>
</div>
</body>
</html>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:1)

这是更新的js块,适合你。但这只会验证长度以及GSTIN是否包含PAN。

var pan = document.getElementById("pan");
var unino = document.getElementById("gstin");
document.getElementById("button").addEventListener("click", function() {
    if (!(unino && unino.length == 15 && unino.indexOf(pan) == 2)){
        alert( pan.value+'&'+res.value );
    }
});

我还应该进行正则表达式验证,以确定HTML格式的正确格式。

平底锅的模式应为 - "[A-Za-z]{5}[0-9]{4}[a-zA-Z]"

对于GSTIN应该是 - "[0-9]{2}[A-Za-z]{5}[0-9]{4}[a-zA-Z][0-9]{1}[a-zA-Z]{1}[0-9]{1}"

答案 1 :(得分:0)

只需在PAN字符串中搜索GST字符串即可。如果它在PAN中找到GST字符串且索引为2,则表示匹配。否则不是。

希望有所帮助。

您可以使用search方法,如下所示

GST.search(PAN);

答案 2 :(得分:0)

我找到了答案。

document.getElementById("button").addEventListener("click", function() {
  var pan = document.getElementById("pan").value;
  
  var unino = document.getElementById("gstin").value;

  var res = unino.substr(2, 10);
  if(pan!=res){
    alert("Wrong GSTIN Number...!");
  }else{
    alert("GST Number is matched.");
  }
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />

<!DOCTYPE html>
<html>
<head>
  <title>Test</title>
</head>
<style type="text/css">

</style>
<body>
<div class="container">
<form method="post">
<div class="form-group">
	<label>PAN</label>
	<div class="input-group">
  <input pattern=".{10,10}" maxlength="10" required="" type="text" class="form-control" name="pan" id="pan"  placeholder="PAN No 10 digist" value="" title="PAN Number must be 10 character"/>
	</div>
</div>

<div class="form-group">
  <label>gstin</label>
  <div class="input-group">
  <input required="" type="text" class="form-control" name="gstin" id="gstin"  placeholder="gstin" value=""/>
  </div>
</div>

<input type="button" name="submit" value="submit" class="btn btn-primary" id="button">
</form>
</div>
</body>
</html>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

答案 3 :(得分:0)

将值传递给函数

//get value of StateCode / PAN Number / GST Number

var chkGstNum = checkGstNumber(stateCode, panNum, gstNum);
if(chkGstNum == 0) // Error Code
else // Success Code 

功能

function checkGstNumber(stateCode, panNum, gstNum)
{
    var GstateCode = gstNum.substr(0, 2);
    var GpanNum = gstNum.substring(2, 12);
    var GEnd = gstNum.substring(12,14);

    if(stateCode != GstateCode)
    {
        alert("Invalid GST Number.");
        return false;
    } 
    if(panNum != GpanNum)
    {
        alert("Invalid GST Number.");
        return false;
    }
    if(GEnd != '1Z')
    {
        alert("Invalid GST Number.");
        return false;   
    }
    if(gstNum.length != 15)
    {
        alert("Invalid GST Number.");
        return false;
    }

    return true;
}