jquery validate案例1

<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-invIncomeInvoice-add">
	<div class="form-group">	
		<label class="col-sm-3 control-label">发票类型:</label>
		<div class="col-sm-8">
			<select id="invoiceType" name="invoiceType" class="form-control m-b">
				<option value="page_special_invoice">增值税专用发票(纸质)</option>
				<option value="page_invoice">增值税普通发票(纸质)</option>
				<option value="elec_invoice">增值税普通发票(电子)</option>
			</select>
		</div>
	</div>
	<div class="form-group">	
		<label class="col-sm-3 control-label">发票代码:</label>
		<div class="col-sm-8">
			<input id="invoiceCode" name="invoiceCode" class="form-control" type="text">
		</div>
	</div>
	<div class="form-group">	
		<label class="col-sm-3 control-label">发票号码:</label>
		<div class="col-sm-8">
			<input id="invoiceNo" name="invoiceNo" class="form-control" type="text">
		</div>
	</div>
	<div class="form-group">	
		<label class="col-sm-3 control-label">开日期:</label>
		<div class="col-sm-8">
			<input id="invoiceDate" name="invoiceDate" class="form-control" type="text">
		</div>
	</div>
	<div class="form-group">	
		<label class="col-sm-3 control-label">价税合计:</label>
		<div class="col-sm-8">
			<input id="totalTax" name="totalTax" class="form-control" type="text" placeholder="增值税专用发票必填">
		</div>
	</div>
	<div class="form-group">	
		<label class="col-sm-3 control-label">校验码:</label>
		<div class="col-sm-8">
			<input id="antiFakeCode" name="antiFakeCode" class="form-control" type="text" placeholder="后六位,增值税普通发票必填">
		</div>
	</div>
		</form>
	</div>
    <div>
    <script type="text/javascript">
		var prefix = ctx + "invoice/invIncomeInvoice"
		$("#form-invIncomeInvoice-add").validate({
			debug: true,
			rules : {
				invoiceCode : {
					required : true,
					check_invoiceCode : true
				},
				invoiceNo : {
					required : true,
					check_invoiceNo : true
				},
				invoiceDate : {
					required : true,
					dateISO : true
				},
				totalTax : {
					required : true,
					check_totalTax : true
				}
			}

		});
		
		
		$.validator.addMethod("check_invoiceCode",function(value,element,params){
				var check = /\d{6,15}$/;
				return this.optional(element)||(check.test(value));
			},"*只允许8-15位数字!");
		$.validator.addMethod("check_invoiceNo",function(value,element,params){
				var check = /\d{6,15}$/;
				return this.optional(element)||(check.test(value));
			},"*只允许8-15位数字!");
		
		$.validator.addMethod("check_totalTax",function(value,element,params){
				var check =  /^\d+\.?\d{0,2}$/;
				var invoiceType = $("#invoiceType").val();
				if(invoiceType=='page_special_invoice'){
					return this.optional(element)||(check.test(value));
				}
				return true;
			},"*保留两位小数的金额!");
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-invIncomeInvoice-add').serialize());
	        }
	    }
	</script>
</body>

73212491b259188d8fa8ae7e5ea01b007af.jpg

转载于:https://my.oschina.net/u/230843/blog/2988008

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值