validate.js 8.3 KB

1
  1. (function(){function h(a,b,c,d){var e=$(a).nextAll().filter("[validate\x3d'"+b+"']");d=$(d);b=$(a).position();0==e.length?$(a).after(d):e.replaceWith(d);d.hide().fadeIn(200);var e=b.left+$(a).outerWidth(!0)+10,f=b.top-(d.outerHeight()-$(a).outerHeight())/2;"0px"!=$(a).css("borderWidth")&&""!=$(a).css("borderWidth")||!$(a).is("input:text")&&!$(a).is("textarea")||(e=b.left+$(a).parent().outerWidth()+5);"left"==c.align||e>$(window).width()-d.outerWidth(!0)?(d.removeClass("top").addClass("left"),e=b.left-d.outerWidth(!0)-10):"top"==c.align&&(f=b.top-d.outerHeight()-15,e=b.left-(d.outerWidth(!0)-$(a).outerWidth(!0))/2,d.removeClass("left").addClass("top"));d.css({left:e+(c.x||0),top:f+(c.y||0)})}function m(a,b){$(a).siblings("img.validate_loading").remove();var c=$(a);c.nextAll().filter("[validate]").remove();strHtml='\x3cdiv class\x3d"validate" validate\x3d"msg" style\x3d"margin-left:3px"\x3e\x3cb class\x3d"b1"\x3e\u25c6\x3c/b\x3e\x3cb class\x3d"b2"\x3e\u25c6\x3c/b\x3e\x3clabel\x3e'+b+"\x3c/label\x3e\x3c/div\x3e";h(c,"msg",{},strHtml);"0px"!=$(c).css("borderWidth")&&""!=$(c).css("borderWidth")||!$(c).is("input:text")&&!$(c).is("textarea")?c.addClass("input_border_red"):c.parent().addClass("input_border_red");c.data("bindClick")||(c.data("bindClick",!0),c.bind("click",function(){$(this).nextAll("[validate]").fadeOut(200)}));var d=c[0],c=d.tagName.toLowerCase();"input"!=c&&"textarea"!=c||setTimeout(function(){d.focus();d.select()},100)}window.common_validate=function(a,b){if($(this).is(":hidden"))return b(),!0;var c=/^1[3|4|5|8][0-9]\d{8}$/,d=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/,e=/(@yahoo.com.cn)|(@yahoo.cn)/,f="";$(this).nextAll().filter("[validate]").remove();$(this).siblings("img.validate_loading").remove();if(a.empty&&""==$.trim(this.value)){f='\x3cdiv class\x3d"validate" validate\x3d"empty"\x3e\x3cb class\x3d"b1"\x3e\u25c6\x3c/b\x3e\x3cb class\x3d"b2"\x3e\u25c6\x3c/b\x3e\x3clabel\x3e'+a.empty+"\x3c/label\x3e\x3c/div\x3e";h(this,"empty",a,f);"0px"!=$(this).css("borderWidth")&&""!=$(this).css("borderWidth")||!$(this).is("input:text")&&!$(this).is("textarea")?$(this).addClass("input_border_red"):$(this).parent().addClass("input_border_red");var g=this;setTimeout(function(){},100);return!1}if(a.express)for(var f=a.express,k=0;k<f.length;k++)if(!f[k].func.call(this))return f='\x3cdiv class\x3d"validate" validate\x3d"express'+k+'" \x3e\x3cb class\x3d"b1"\x3e\u25c6\x3c/b\x3e\x3cb class\x3d"b2"\x3e\u25c6\x3c/b\x3e\x3clabel\x3e'+f[k].text+"\x3c/label\x3e\x3c/div\x3e",h(this,"express"+k,a,f),"0px"!=$(this).css("borderWidth")&&""!=$(this).css("borderWidth")||!$(this).is("input:text")&&!$(this).is("textarea")?$(this).addClass("input_border_red"):$(this).parent().addClass("input_border_red"),g=this,$(g).is("input:text")&&setTimeout(function(){},100),!1;if(a.phone&&!c.test(this.value.replace(/\s/g,""))&&""!=this.value)f='\x3cdiv class\x3d"validate" validate\x3d"phone" \x3e\x3cb class\x3d"b1"\x3e\u25c6\x3c/b\x3e\x3cb class\x3d"b2"\x3e\u25c6\x3c/b\x3e\x3clabel\x3e'+a.phone+"\x3c/label\x3e\x3c/div\x3e",h(this,"phone",a,f),"0px"!=$(this).css("borderWidth")&&""!=$(this).css("borderWidth")||!$(this).is("input:text")&&!$(this).is("textarea")?$(this).addClass("input_border_red"):$(this).parent().addClass("input_border_red"),g=this,setTimeout(function(){g.focus();g.select()},100);else if(a.email&&!d.test(this.value)&&""!=this.value)f='\x3cdiv class\x3d"validate" validate\x3d"email" \x3e\x3cb class\x3d"b1"\x3e\u25c6\x3c/b\x3e\x3cb class\x3d"b2"\x3e\u25c6\x3c/b\x3e\x3clabel\x3e'+a.email+"\x3c/label\x3e\x3c/div\x3e",h(this,"email",a,f),"0px"!=$(this).css("borderWidth")&&""!=$(this).css("borderWidth")||!$(this).is("input:text")&&!$(this).is("textarea")?$(this).addClass("input_border_red"):$(this).parent().addClass("input_border_red"),g=this,setTimeout(function(){g.focus();g.select()},100);else if(a.email&&e.test(this.value)&&""!=this.value)f='\x3cdiv class\x3d"validate" validate\x3d"email" \x3e\x3cb class\x3d"b1"\x3e\u25c6\x3c/b\x3e\x3cb class\x3d"b2"\x3e\u25c6\x3c/b\x3e\x3clabel\x3e'+a.yahooEmail+"\x3c/label\x3e\x3c/div\x3e",h(this,"email",a,f),"0px"!=$(this).css("borderWidth")&&""!=$(this).css("borderWidth")||!$(this).is("input:text")&&!$(this).is("textarea")?$(this).addClass("input_border_red"):$(this).parent().addClass("input_border_red"),g=this,setTimeout(function(){g.focus();g.select()},100);else{if(a.noSuccess)return!0;var n=function(a,c){b&&b();if(""==a.value)return"0px"!=$(a).css("borderWidth")&&""!=$(a).css("borderWidth")||!$(a).is("input:text")&&!$(a).is("textarea")?$(a).removeClass("input_border_red"):$(a).parent().removeClass("input_border_red"),!0;$(a).nextAll("[validate]").remove();"0px"!=$(a).css("borderWidth")&&""!=$(a).css("borderWidth")||!$(a).is("input:text")&&!$(a).is("textarea")?$(a).removeClass("input_border_red"):$(a).parent().removeClass("input_border_red");return!0};if(c=a.callback){var l=this;$(l).parent().find(":last").after("\x3cimg class\x3d'validate_loading' src\x3d'/images/validate_loading.gif'/\x3e");c.call(l,function(b,c){b?($(l).siblings("img.validate_loading").remove(),n(l,a)):m(l,c)});return 1}return n(this,a)}};window.email_auto=function(a){a=$(a);var b,c;0==$("#login_autoComplete").length?($("body").append('\x3cdiv class\x3d"login_autoComplete" id\x3d"login_autoComplete"\x3e\t\t\x3cul class\x3d"login_auto_ul"\x3e\t\t\t\x3cli class\x3d"login_auto_title"\x3e\u8bf7\u9009\u62e9\u90ae\u7bb1\u540e\u7f00\x3c/li\x3e\t\t\t\x3cli class\x3d"hover" hz\x3d"@qq.com"\x3e\x3c/li\x3e\t\t\t\x3cli hz\x3d"@163.com"\x3e\x3c/li\x3e\t\t\t\x3cli hz\x3d"@126.com"\x3e\x3c/li\x3e\t\t\t\x3cli hz\x3d"@sina.com"\x3e\x3c/li\x3e\t\t\t\x3cli hz\x3d"@21cn.com"\x3e\x3c/li\x3e\t\t\x3c/ul\x3e\t\x3c/div\x3e'),$("#login_autoComplete").data("elt",a),b=$("#login_autoComplete"),c=b.find("li:not(.login_auto_title)"),c.mouseover(function(){$(this).siblings().filter(".hover").removeClass("hover");$(this).addClass("hover")}).mouseout(function(){$(this).removeClass("hover")}).mousedown(function(){$("#login_autoComplete").data("elt").val($(this).text()).change();$(this).parent().parent().hide()})):($("#login_autoComplete").data("elt",a),b=$("#login_autoComplete"),c=b.find("li:not(.login_auto_title)"));$("#login_autoComplete").css("width",a.outerWidth()-1);a.keyup(function(a){if(/13|38|40|116/.test(a.keyCode)||""==this.value)return!1;var e=this.value;if(-1==e.indexOf("@"))return b.hide(),!1;c.each(function(){this.innerHTML=e.replace(/\@+.*/,"")+$(this).attr("hz");0<=this.innerHTML.indexOf(e)?$(this).show():$(this).hide()}).filter(".hover").removeClass("hover");b.show().css({left:$(this).offset().left,top:$(this).offset().top+$(this).outerHeight(!0)-1});0==c.filter(":visible").length?b.hide():c.filter(":visible").eq(0).addClass("hover")}).change(function(){$("#login_autoComplete").hide()}).keydown(function(a){38==a.keyCode?c.filter(".hover").prev().not(".login_auto_title").addClass("hover").next().removeClass("hover"):40==a.keyCode?c.filter(".hover").next().addClass("hover").prev().removeClass("hover"):13==a.keyCode&&c.filter(".hover").mousedown()}).focus(function(){$("#login_autoComplete").data("elt",$(this))})};UI.extend.validate=function(a){var b={active:null,phone:null,email:null,empty:null,length:null,pass:""};$.extend(b,a);(b.active||""===b.active)&&$(this).focus(function(){if(!(0<(b.position&&/^[^\:]+/.test(b.position)?$(b.position+" .zhfs_state:visible"):$(this).nextAll().filter(".zhfs_state:visible")).length)){var a=b.className?b.className:"";b.active&&h(this,"active",b,'\x3cspan class\x3d"zhfs_state zhfs_v_info '+a+'" validate\x3d"active" \x3e\x3ci\x3e\x3c/i\x3e\x3clabel class\x3d"label_tip"\x3e'+b.active+"\x3c/label\x3e\x3c/span\x3e");$(this).addClass("login_input_color")}}).blur(function(){b.position&&/^[^\:]+/.test(b.position)?$(b.position+" [validate\x3d'active']").hide():$(this).nextAll().filter("[validate\x3d'active']").hide();$(this).removeClass("login_input_color")});b.length&&(a={text:b.length.text,func:function(){var a=b.length;return void 0!=a.min&&this.value.length<a.min||void 0!=a.max&&this.value.length>a.max?!1:!0}},b.express?b.express.push(a):b.express=[a]);if(b.phone||b.empty||b.email||b.express)$(this).click(function(){this.ischange||$(this).not("input:text").next("[validate]").fadeOut(200);this.ischange=void 0}),$(this).change(function(){var a=this;setTimeout(function(){a.ischange=!0;var d={},e;for(e in b)d[e]=b[e];common_validate.call(a,d)})}),b.email&&email_auto(this)};window.error_tip=m})(jQuery);