demo.js 2.67 KB
jQuery.validator.addMethod("isLock", function(value, element) {
	var lock = /[A-Z]/;
	return this.optional(element) || (!lock.test(value));
}, "Email不能有大写字母");
function validateRight(str, id){
	$("#"+id+"_dl").attr('class','tips-box-error');
	$("#c_"+id).hide('fast');
	return '<span class="tips-error">'+str+'</span>';
}
$(document).ready(function(){
	$('input').focus(function(){
		var cls = $('#'+this.id).attr('class');
		if(cls != 'input_1 error'){
			$("#"+this.id+"_dl").attr('class','tips-box-text');
		}
	}); 
	$('input').blur(function() {
		var cls = $('#'+this.id).attr('class');
		if(cls != 'input_1 error'){
			$("#"+this.id+"_dl").removeClass();
		}
	});
});
$().ready(function() {
	$("#registerForm").validate({
		debug:true,
		// onclick:false,
		// onkeyup:false,
		// focusInvalid:false,
		// onkeyup:false,
		// errorElement : "span",
		// errorClass:"tips-error",
		rules : {
			email : {
				required : true,
				minlength : 6,
				email : true,
				isLock : true
				// remote : "/passport/reg/authmail"
			},
			password : {
				required : true,
				minlength : 6,
				maxlength : 30
			},
			confirm_password : {
				required : true,
				minlength : 6,
				equalTo : "#password"
			},
			auth_code : {
				required : true,
				// remote : "/passport/images/verifyimgcode",
				minlength : 4,
				maxlength : 4
			}
		},
		messages : {
			email : {
				required : function(val, obj){
					return validateRight( "此邮箱将作为您的登录邮箱!" ,obj.id); 
				},
				minlength : function(val, obj){
					return validateRight( "Email地址太短,最少6位!" ,obj.id);
				},
				email : function(val, obj){
					return validateRight("请填写正确的格式" ,obj.id); 
				},
				// remote : "已经被注册或错误的Email!"
			},
			password : {
				required : "请输入密码!",
				minlength : jQuery.format("你的密码太短,最少{0}位!"),
				maxlength : jQuery.format("密码最长{0}位")
			},
			confirm_password : {
				required : "请输入确认密码!",
				minlength : "确认密码太短!",
				equalTo : "确认密码不正确,请重新输入."
			},
			auth_code : {
				required : '请输入验证码.',
				// remote : "验证码错误.",
				minlength : jQuery.format("验证码{0}位."),
				maxlength : jQuery.format("验证码{0}位.")
			}
		},
		success:function(label){
			var htmlfor = label.attr('for');
			var cls = $('#'+htmlfor).attr('class');
			if(cls != 'input_1 valid'){
				$("#c_"+htmlfor).show('fast',function(){
					$("#"+htmlfor+"_dl").attr('class','tips-box-text');
					$("#c_"+htmlfor).attr('class','tips-right');
				});
				// label.after('<span id="'+htmlfor+'_right"
				// class="tips-right">正确提示</span>');
			}
		}

	});
});