//js下载地址 http://yl96.cn/statics/js/jquery.validate.js
$(function(){
$("#formID").validate({ //表单id
rules:{
username:{
required: true,
minlength:2,
maxlength:20,
remote:{ //验证用户名是否存在
type : "post",
url : "<?php echo site_url('init/public_checkname_ajax')?>",
data:{
username:function(){
return $("#username").val();
},
rand:function(){
return Math.random();
}
}
}
},
password:{
required: true,
minlength:6,
maxlength:20
},
pwdconfirm:{
required: true,
minlength:6,
maxlength:20,
equalTo:"#password"
},
email:{
required:true,
email: true,
remote:{ //验证邮箱是否存在
type : "post",
url : "<?php echo site_url('init/public_checkemail_ajax')?>",
data:{
email:function(){
return $("#email").val();
},
rand:function(){
return Math.random();
}
}
}
},
phone:{
required:true,
phone: true,
remote:{ //验证手机是否存在
type : "post",
url : "<?php echo site_url('init/public_checkphone_ajax')?>",
data:{
phone:function(){
return $("#phone").val();
},
rand:function(){
return Math.random();
}
}
}
},
hospital:{
required: true,
minlength:2
},
subject:{
required: true,
minlength:2
}
},
messages: {
username: {
required: "请输入用户名",
minlength: jQuery.format("用户名不能小于{0}个字符"),
remote:jQuery.format("用户名已经被注册")
},
password:{
required: "请输入密码",
minlength: jQuery.format("密码不能小于{0}个字符")
},
pwdconfirm:{
required: "请输入确认密码",
minlength: "确认密码不能小于{0}个字符",
equalTo: "两次输入密码不一致不一致"
},
email:{
required: "请输入Email地址",
email: "请输入正确的email地址",
remote:jQuery.format("邮箱已经被注册")
},
phone:{
required: "请输入手机号",
phone: "请输入正确的手机号",
remote:jQuery.format("手机号已经被注册")
},
hospital:{
required: "请输入医院",
minlength: jQuery.format("请输入医院")
},
subject:{
required: "请输入科室",
minlength: jQuery.format("请输入科室")
}
},
errorClass: "help-inline",
errorElement: "span",
highlight:function(element, errorClass, validClass) {
$(element).parents('.control-group').removeClass('success');
$(element).parents('.control-group').addClass('error');
},
unhighlight: function(element, errorClass, validClass) {
$(element).parents('.control-group').removeClass('error');
$(element).parents('.control-group').removeClass('success');
},
onfocusout: function(element) { $(element).valid(); }
});
})