jQuery 财务代码验证
Posted
技术标签:
【中文标题】jQuery 财务代码验证【英文标题】:jQuery fiscal code validation 【发布时间】:2016-09-06 08:04:49 【问题描述】:我遇到了一些关于财政代码验证功能的问题,我是 Bootstrap 和 jquery 的新手,在互联网上进行了一些搜索,我尝试了这样的事情:
<script type="text/javascript">
jQuery.validator.addMethod("codfiscale", function(id)
var regex = /[A-Z]6[\d]2[A-Z][\d]2[A-Z][\d]3[A-Z]/;
return value. match(regex);
, "Please insert a valid italian identification number");
</script>
这就是形式:
<form id="form">
<div id="form" class="form-group col-md-4 col-md-offset-4">
<label for="id">Codice fiscale:</label>
<input type="text" name="id" class="codfiscale"/>
</div>
<div class="form-group col-md-4 col-md-offset-4">
<label for="exampleInputPassword1">Password:</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<div class="form-group col-md-4 col-md-offset-4" class="col-md-3">
<button type="submit" OnClick="codfiscale" value="id" class="btn btn-primary center-block">Submit</button>
</div>
</form>
感谢您的帮助!
【问题讨论】:
Si, Questi sono i 4 plugin che in generale leggo siano quelli necessari per la validazione: jquery.delegate.js,jquery.metadata.js,,jquery.validate.min.js, form-validation .js scusa mi fai vedere come richiami il validate? 【参考方案1】:假设您使用的是来自 html.it
的示例<script type="text/javascript">
jQuery.validator.addMethod("codfiscale", function(value)
var regex = /[A-Za-z]6[0-9lmnpqrstuvLMNPQRSTUV]2[abcdehlmprstABCDEHLMPRST]1[0-9lmnpqrstuvLMNPQRSTUV]2[A-Za-z]1[0-9lmnpqrstuvLMNPQRSTUV]3[A-Za-z]1/;
return value. match(regex);
, "Please insert a valid italian identification number");
$(document).ready(function()
$("#form").validate();
);
</script>
<form id="form">
<div class="form-group col-md-4 col-md-offset-4">
<label for="id">Codice fiscale:</label>
<input type="text" name="id" class="form-control codfiscale required"/>
</div>
<div class="form-group col-md-4 col-md-offset-4">
<label for="exampleInputPassword1">Password:</label>
<input type="password" name="exampleInputPassword1" class="form-control required" placeholder="Password">
</div>
<div class="form-group col-md-4 col-md-offset-4" class="col-md-3">
<button type="submit" class="btn btn-primary center-block">Submit</button>
</div>
</form>
【讨论】:
【参考方案2】:你可以试试这个:
<div>FISCAL ID: <input type="text" name="name" required pattern="[A-Z]6\d2[A-E,H,L,M,P,R,S,T]1\d2[A-Z]1\d3[A-Z]1" /></div>
<style>
input:required:invalid background-color: lightcoral;
input:required:valid background-color: lightgreen;
</style>
【讨论】:
以上是关于jQuery 财务代码验证的主要内容,如果未能解决你的问题,请参考以下文章
[转]jQuery.validate插件在失去焦点时执行验证代码