首页 > 代码库 > cv.form.validator

cv.form.validator

有即时验证,加载完验证两种方式:
即时验证:

cv.form.validator(jQuery("#qq").val(),{
	  type:["require","intlength","int"],min:5,max:11,
	  errorFunction:function(obj,options){
		  switch(options.type){
			case "require" :{
				jQuery("#msg_qq").attr("class","tips_error").html("请输入常用的QQ号码!").show();
				break;
			}
			case "intlength" :{
				jQuery("#msg_qq").attr("class","tips_error").html("请输入常用的QQ号码!").show();
				break;
			}
			case "int":{
				jQuery("#msg_qq").attr("class","tips_error").html("请输入正确的QQ号码!").show();
				break;
			}
		}
	  },
	  successFunction:function(obj,options){
		  jQuery("#msg_qq").attr("class","tips_ok").html("").show();
	  }
});



加载完统一验证:
cv.form.validator.bind(jQuery("#shortTitle"),{
	type:["require"],
	successFunction:function(obj,options){
		_showMsg("#msg_shortTitle","tips_ok","");
	},
	errorFunction:function(obj,options){
		switch(options.type){
			case "require":{
				 _showMsg("#msg_shortTitle","tips_error","信息标题不能为空!");
				break;
			}
		}
	}
});
jQuery("#shortTitle").bind("blur",function(){
	if(jQuery("#shortTitle").val()){
		cv.form.validator(this);
	}
}).bind("focus",function(){
	 _showMsg("#msg_shortTitle","tips_info","请填写信息标题。");
});






cv.form.validator