Jquery表单验证插件–Validform

Validform:

Jquery表单验证插件–Validform:一行代码搞定整站的表单验证!

Validform 官网

 

jquery.form.js:

jquery.form.js中的ajaxSubmit

 

1.

<script src="/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/js/Validform_v5.3.2_min.js"></script>
<script src="/js/jquery.form.js"></script>

<form action="/union/saveJoin.do" method="post" id="form1" class="registerform">
	<table border="0" cellpadding="0" cellspacing="1" width="800" >	
		<tr>
			<td width="200" height="40" align="right" valign="middle" style="padding-right: 20px;">* 姓名 </td>
			<td width="600" valign="middle"><input class="shout" type="text" name="username" id="username" datatype="s2-12" errormsg="姓名至少2个字符,最多12个字符!" nullmsg="请填写姓名!" ></td>
		</tr>
		<tr>
			<td width="200" height="40" align="right" valign="middle" style="padding-right: 20px;">* 手机 </td>
			<td width="600" valign="middle"><input class="shout" type="text" name="mobile" id="mobile" datatype="m" errormsg="手机号码格式不正确!" nullmsg="请填写手机号码!"></td>
		</tr>
		<tr>
			<td width="200" height="40" align="right" valign="middle" style="padding-right: 20px;">* 邮箱 </td>
			<td width="600" valign="middle"><input type="text" name="email" id="email" datatype="e" errormsg="邮箱格式不正确!" nullmsg="请填写邮箱!"></td>
		</tr>
		<tr>
			<td width="200" height="40" align="right" valign="middle" style="padding-right: 20px;">* 身份证号 </td>
			<td width="600" valign="middle"><input type="text" name="idcard" id="idcard" datatype="*"  nullmsg="请填写身份证号!"></td>
		</tr>						
		
		<tr>
			<td width="200" height="60" align="right" valign="middle" style="padding-right: 20px;"> </td>
			<td width="600" valign="middle">
				<input class="btn" type="submit" value="提交资料">
			</td>
		</tr>
	</table>
	<span id="checkButton"></span>
</form>

 

JS :

$(function() {
	$(".registerform").Validform({
    	btnSubmit:"#checkButton",
    	tiptype:function(msg){
			if(msg != ''){
				showmsg(msg);
			}
		},
		tipSweep:true,
		beforeSubmit:function(){
			saveAccount();
			return false;
		}
	});
});

function saveAccount(){
	
	$("#form1").ajaxSubmit(function(data) {
		data = eval('(' + data + ')');
		if(data.code == 0){	
		}else if(data.code == -1){			
		}else{
			alert("系统繁忙,请稍后重试!");
		}
	 });
	
	return false;
}

 

...

 

你可能感兴趣的:(jquery)