FROM : http://mangege.iteye.com/blog/1001984
$.validator.setDefaults({
submitHandler: function() { alert("submitted!");return false; }
});
$().ready(function() {
// validate signup form on keyup and submit
$("#reg_form").validate({
rules: {
/* input name 有 . 时加上引号 */
'mem.username': {
required: true,
minlength: 5
},
'mem.password': {
required: true,
minlength: 5
}
},
messages: {
'mem.username': {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
'mem.password': {
required: "Please provide a password2",
minlength: "Your password must be at least 5 characters long"
}
},
/* 重写错误显示消息方法,以alert方式弹出错误消息 */
showErrors: function(errorMap, errorList) {
var msg = "";
$.each( errorList, function(i,v){
msg += (v.message+"\r\n");
});
if(msg!="") alert(msg);
},
/* 失去焦点时不验证 */
onfocusout: false
});
});