如下的代码,提交时没有经过验证,就直接提交了。
修改为如下的代码,验证就可以了。
代码如下:
<script language="javascript">
var attribute = {
rules: {
"entity.name":{
required: true,
minlength: 2
},
"entity.realName":{
required: true,
minlength: 2
},
"entity.postalcode":{
maxlength: 6,
number: true
},
"entity.phone":{
required: true,
minlength: 7
},
"entity.email":{
codeCheck:true,
required: true,
remote: {url:"json_personMsg_checkEmail.do?ran="+Math.random(),
data:{
"entity.uid":function() {return $("#entity_id").val();}
}},
email: true
}
},
messages: {
"entity.name":{
required:"用户名不能为空!",
minlength:jQuery.format("最少输入{0}字符或汉字")
},
"entity.realName":{
required:"真实姓名不能为空!",
minlength:jQuery.format("最少输入{0}字符或汉字")
},
"entity.postalcode":{
maxlength: "最大不能超过{0}数字",
number: "邮编为数字"
},
"entity.phone":{
required: "办公电话不能为空!",
minlength: jQuery.format("最小长度为{0}")
},
"entity.email":{
required: "电子邮件地址不能为空",
remote:"电子邮件地址已存在,请重新输入",
email: "请按格式输入电子邮件地址"
}
},
errorPlacement: function(error, element) {
if (element.next().size()==0) {
error.appendTo(element.parent());
} else {
error.appendTo(element.next());
}
},
submitHandler: function() {
$.blockUI({ message: '<div id="msgDiv"><h2><img src="common/images/busy.gif" />正在提交,请稍后...</h2></div>'});
document.form1.submit();
},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set as text for IE
label.html(" ").addClass("checked");
}
};
$(document).ready(function(){
alertMessage();
exclusiveCN();
var validator = $("#form1").validate(attribute);
});
</script>