我有以下表格。我正在尝试使用 jquery 验证插件来验证输入。我尝试了一些代码,但它不起作用。当我单击提交按钮时,它只是进入表单的操作。
<form name="voucherform" action="something" method="post">
<input type="text" name="reg_number[]" value="" />
<input type="text" name="reg_number[]" value="" />
<input type="text" name="reg_number[]" value="" />
<input type="submit" name="submit" value="submit" />
您能否告诉我如何使用 jquery 验证插件来验证上述表单?
谢谢 :)
我的jQuery代码:
<script type="text/javascript" src="<?php echo base_url();?>support/datepicker/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>support/js/jquery.validate.js"></script>
<script>
$(document).ready(function() {
// validate signup form on keyup and submit
var validator = $("#voucherform").validate({
showErrors: function(errorMap, errorList) {
$(".errormsg").html($.map(errorList, function (el) {
return el.message;
}).join(", "));
},
wrapper: "span",
rules: {
reg_number[]: {
required: true,
minlength: 2,
remote: {
url: '<?php echo base_url();?>sales/invoice_check', async: false,
type: 'post'
},
}
},
messages: {
reg_number[]: {
required: "Enter Reg Number",
minlength: jQuery.format("Enter at least {0} characters"),
remote: jQuery.format("{0} is already in use")
},
}
});
});
</script>