/ruhlamat_website/Inc/jsvalidator/js/JSValidator_v1.0.js
JavaScript | 783 lines | 665 code | 40 blank | 78 comment | 69 complexity | 5892cbe814b76888311608fc0076d8fb MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
- <!--
-
- var JSValidator={
- /***?????????????????????**/
- setup:function(formid){
- var targetForm=JSValidator.Tools.$(formid); //????????
- var tagArr = targetForm.getElementsByTagName("my:tag"); //?????????
- //alert("??????:"+tagArr.length);
- //??????? ????
- for(var i=0;i<tagArr.length;i++){
- ValidateFactory.GetValidateField(tagArr[i],i);
- }
- /**????? onsubmit?? ??*/
- JSValidator.Tools.AddEventFunc(targetForm,"onsubmit",JSValidator.validateBeforeSub,tagArr);
- },
-
- /**??????????**/
- tipuser:function(formElement){
- //?? ???????
- var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
- // ???tag?? ??? Bean
- var Bean = new JSValidator.validateBean();
- Bean.initTag(tag);
- JSValidator.Message.Show(Bean,"tips");
- },
-
- /**????????????**/
- validateForm:{
- submit:true //???????
- },
-
- /**? ?????? ??**/
- validateBeforeSub:function(targetForm,tags){
- //??? ???????
- JSValidator.validateForm.submit = true;
- for(var i=0;i<tags.length;i++){
- var Bean = new JSValidator.validateBean();
- Bean.initTag(tags[i]);
- var s1 = Bean.getRule().indexOf("||");
- var s2 = Bean.getRule().indexOf("&&");
- var operate="";
- /**???? ?????? ? ????? ????**/
- if((s1!=-1)||(s2!=-1)){ //???????????
- if(Bean.getRule().indexOf("compare")!=-1){
- throw new Error("rule??????????'copare'????????????rule????");
- return false;
- }else if(Bean.getRule().indexOf("custom")!=-1){
- throw new Error("rule??????????'custom'????????????rule????");
- return false;
- }else if(s1!=-1&&s2!=-1){
- throw new Error("rule???????????????? ????????rule????");
- return false;
- }else{
- operate = s1!=-1?"||":"&&"; //?????
- }
- }
-
- switch(Bean.getRule()){
- case "limit":
- JSValidator.Core.valForLimit(JSValidator.Tools.$(Bean.getFor()));
- break;
- case "compare":
- JSValidator.Core.valForCompare(JSValidator.Tools.$(Bean.getFor()));
- break;
- case "custom":
- JSValidator.Core.valForCustom(JSValidator.Tools.$(Bean.getFor()));
- break;
- default :
- /***????????? ?????? onblur??****/
- JSValidator.Core.validate(JSValidator.Tools.$(Bean.getFor()),operate);
- break;
- }
- }
- },
-
- /**?????????***/
- regulation:{
- /**???????**/
- simple:{
- notempty : /.+/,//???
- email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,//email??
- phone : /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/,//?????????????
- mobile : /^((\(\d{2,3}\))|(\d{3}\-))?((13\d{9})|(15[389]\d{8}))$/,//????
- url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"])*$/,//url??
- ip : /^(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])$/,//ip????
- currency : /^\d+(\.\d+)?$/,//????
- number : /^\d+$/,//????
- zip : /^[1-9]\d{5}$/,//??????
- qq : /^[1-9]\d{4,8}$/,//??QQ???5~9?
- english : /^[A-Za-z]+$/,//????
- chinese : /^[\u0391-\uFFE5]+$/,//??
- username : /^[a-z]\w{3,19}$/i,//???????????3~19???
- password : /^\w{8,19}$/i,
- integer : /^[-\+]?(?:\d|[1-9]\d+)$/,//????
- double : /^[-\+]?(?:\d|[1-9]\d+)(\.\d+)?$/,//??????????????
- date:/^(19\d{2}|2\d{3})-(0?[1-9]|1[0-2])-((0?[1-9])|((1|2)[0-9])|30|31)$/, //????
- datetime:/^(19\d{2}|2\d{3})-(0?[1-9]|1[0-2])-((0?[1-9])|((1|2)[0-9])|30|31) ((0?\d)|(1\d|2[0-3]))(:(0?\d|[1-5]\d)){2}$/ //??????
- },
- /**???????*/
- complex:{
- compare:function(source,target,type,mode){//target???source?? ,type:???? mode?????
- var reg = null;
- var result = false;
- // ???
- if(type=="string"){
- switch(mode){
- case "equal":
- reg = new RegExp("^"+source+"$","i");
- break;
- case "notequal":
- reg = new RegExp("^"+source+"$","i");
- result = !reg.test(target);
- reg = null;
- break;
- case "greaterthan":
- result = source>target;
- break;
- case "greaterthanequal":
- result = source>=target;
- break;
- case "lessthan":
- result = source<target;
- break;
- case "lessthanequal":
- result = source<=target;
- break;
- }
- }
- // ??
- else if(type=="number"){
- if(isNaN(source)){return false;}
- var sr = parseFloat(source);
- var tg = parseFloat(target);
- switch(mode){
- case "equal":
- result = sr==tg;
- break;
- case "notequal":
- result = sr!=tg;
- break;
- case "greaterthan":
- result = sr>tg;
- break;
- case "greaterthanequal":
- result = sr>=tg;
- break;
- case "lessthan":
- result = sr<tg;
- break;
- case "lessthanequal":
- result = sr<=tg;
- break;
- }
- }
- //??
- else{
- var sr = JSValidator.Tools.GetDateFromStr(source);
- var tg = JSValidator.Tools.GetDateFromStr(target);
- var b = (!(sr>tg))&&(!(sr<tg));
- switch(mode){
- case "equal":
- result = b;
- break;
- case "notequal":
- result = !b;
- break;
- case "greaterthan":
- result = (sr>tg&&b==false);
- break;
- case "greaterthanequal":
- result = (sr>tg||b==true);
- break;
- case "lessthan":
- result = (sr<tg&&b==false);
- break;
- case "lessthanequal":
- result = (sr<tg||b==true);
- break;
- }
- }
- result = reg?reg.test(target):result;
- reg=null;
- return result;
- },
-
- limit:function(source,Bean){
- var res = true;
- for(var v in Bean["limits"]){
- if(Bean["limits"][v]!=null){
- b = this.testLimit(source,Bean.getAs(),Bean["limits"],v);
- if(b==false){
- res = false;
- break;
- }
- }
- }
- return res;
- },
-
- custom:function(source,expression){
- var reg = new RegExp(expression);
- return reg.test(source);
- },
- // ?? ???? ???????
- testLimit:function(value,type,option,limits){
- var reg = null;
- var result = false;
- var str ="";
- if(type=="string"){ //??
- switch(limits){
- case "min":
- reg = new RegExp("^.{"+option["min"]+",}$"); //??? ????
- break;
- case "max":
- reg = new RegExp("^.{0,"+option["max"]+"}$"); //??? ????
- break;
- case "enum": //??? ?,??
- str="";
- var enums = option["enum"].split(",");
- for(var v in enums){
- str+=enums[v]+"|";
- }
- str = str.substring(0,str.length-1);
- reg = new RegExp("^(?:"+str+")$");
- break;
- case "except": //??? ?,??
- str="";
- var excepts = option["except"].split(",");
- for(var v in excepts){
- str+=excepts[v]+"|";
- }
- str = str.substring(0,str.length-1);
- reg = new RegExp("^(?:"+str+")$");
- result = reg.test(value)?false:true;
- reg = null;
- break;
- case "beginwith": //????,??
- str="";
- var begins = option["beginwith"].split(",");
- for(var v in begins){
- str+=begins[v]+"|";
- }
- str = str.substring(0,str.length-1);
- reg = new RegExp("^(?:"+str+").*$","i");
- break;
- case "endwith": //????,??
- str="";
- var ends = option["endwith"].split(",");
- for(var v in ends){
- str+=ends[v]+"|";
- }
- str = str.substring(0,str.length-1);
- reg = new RegExp("^.*(?:"+str+")$","i");
- break;
- }
- }else if(type=="number"){ //??
- switch(limits){
- case "min":
- result = parseFloat(option["min"])<=parseFloat(value);
- break;
- case "max":
- result = parseFloat(option["max"])>=parseFloat(value);
- break;
- case "enum":
- var enums = option["enum"].split(",");
- for(var v in enums){
- if(parseFloat(enums[v])==parseFloat(value)){ // ??? ?????????
- result = true;
- return;
- }
- }
- break;
- case "except":
- var excepts = option["except"].split(",");
- var b = true;
- for(var v in excepts){
- if(parseFloat(excepts[v])==parseFloat(value)){ // ??? ?????????
- b = false;
- return;
- }
- }
- result = b;
- break;
- case "format": //???? ?? ???
- var format = option["format"];
- format = format.split(".");
- //???? ?? ??? '*'??
- var zheng = format[0]!="*"?"[1-9]\\d{"+(format[0].length-1)+"}":"*";
- zheng = format[0].length<2?(format[0]=="*"?"0|[1-9]\\d*":"\\d"):zheng;
- var fu ="{0}";
- fu =format.length==2?(format[1]=="*"?"*":"{"+format[1].length+"}"):fu;
- reg =fu==0?new RegExp("^[+\\-]?"+zheng+"$"):new RegExp("^[+\\-]?"+zheng+"\\.\\d"+fu+"$");
- break;
- }
- }else{ //??
- var sr = JSValidator.Tools.GetDateFromStr(value);
- var b = false;
- switch(limits){
- case "min":
- var min = JSValidator.Tools.GetDateFromStr(option["min"]);
- b = (!(min>sr))&&(!(min<sr));
- result = (sr>min||b==true);
- break;
- case "max":
- var max = JSValidator.Tools.GetDateFromStr(option["max"]);
- b = (!(max>sr))&&(!(max<sr));
- result = (sr<max||b==true);
- break;
- case "enum":
- b = false;
- enums = option["enum"].split(",");
- for(var v in enums){
- var date = JSValidator.Tools.GetDateFromStr(enums[v]);
- b = (!(date>sr))&&(!(date<sr));
- if(b==true){
- b= true;
- break;
- }
- }
- result= b;
- break;
- case "except":
- b = true;
- excepts = option["except"].split(",");
- for(var v in excepts){
- var date = JSValidator.Tools.GetDateFromStr(excepts[v]);
- b = (!(date>sr))&&(!(date<sr));
- b =!b;
- if(b==false){
- b = false;
- break;
- }
- }
- result = b;
- break;
- }
- }
- result = reg?reg.test(value):result;
- return result; //??????
- }
- }
- },
- /**????????????**/
- validateBean:function(){
- var _id = null; // ?????id
- var _for = null; // ????????? id
- var _rule = null; // ?? ???? ??
- var _pass = null; // ????? ?????
- var _error = null; // ????? ?????
- var _tips = null; // ?? ????? ?????
- var _empty = null; // ?? ????? ??????????
- var _require = "true"; // ?? ?? ???????
- var _to = null; // ?????? ????? id
- var _format = null; // ?????? ?????
- var _min = null; // ???????
- var _max = null; // ???????
- var _as = "string"; // ?? ??????string:??? number:?? date:???
- var _mode = "equal"; // ?????(=?>,<,!=,>=,<=)
- var _enum =null; // ???
- var _except =null; // ???
- var _expression=null; // ?????
- var _beginwith = null; //? ????
- var _endwith = null; //? ????
-
- //???? ???? ??????
- this.empty = _empty;
- this.tips = _tips;
- this.error = _error;
- this.pass = _pass;
- this.temp = "";
-
- this.limits = []; //?? ??????????
-
- this.getId=function(){return _id;}
- this.setId=function(p0){_id=p0;}
- this.getFor=function(){return _for;}
- this.setFor=function(p0){_for=p0;}
- this.getRule=function(){return _rule;}
- this.setRule=function(p0){_rule = p0;}
- this.getPass=function(){return _pass;}
- this.setPass=function(p0){_pass = p0;}
- this.getError=function(){return _error;}
- this.setError=function(p0){_error = p0;}
- this.getTips=function(){return _tips;}
- this.setTips=function(p0){_tips = p0;}
- this.getEmpty=function(){return _empty;}
- this.setEmpty=function(p0){_empty = p0;}
- this.getRequire=function(){return _require;}
- this.setRequire=function(p0){if(JSValidator.Tools.Exists(p0)){_require = p0;}}
- this.getTo=function(){return _to;}
- this.setTo=function(p0){_to = p0;}
- this.getFormat=function(){return _format;}
- this.setFormat=function(p0){_format = p0;}
- this.getMin=function(){return _min;}
- this.setMin=function(p0){_min = p0;}
- this.getMax=function(){return _max;}
- this.setMax=function(p0){_max = p0;}
- this.getAs=function(){return _as;}
- this.setAs=function(p0){_as = p0;}
- this.getMode=function(){return _mode;}
- this.setMode=function(p0){_mode = p0;}
- this.getEnum=function(){return _enum;}
- this.setEnum=function(p0){_enum = p0;}
- this.getExcept=function(){return _except;}
- this.setExcept=function(p0){_except = p0;}
- this.getExpression=function(){return _expression;}
- this.setExpression=function(p0){_expression = p0;}
- this.getBeginwith=function(){return _beginwith;}
- this.setBeginwith=function(p0){_beginwith = p0;}
- this.getEndwith=function(){return _endwith;}
- this.getEndwith=function(p0){_endwith = p0;}
-
- //??????
- this.initTag=function(tag){
- _id = JSValidator.Tools.Exists(tag.getAttribute("id"))?tag.getAttribute("id"):_id;
- _for = JSValidator.Tools.Exists(tag.getAttribute("for"))?tag.getAttribute("for"):_for;
- _rule = JSValidator.Tools.Exists(tag.getAttribute("rule"))?tag.getAttribute("rule"):_rule;
- _pass = JSValidator.Tools.Exists(tag.getAttribute("pass"))?tag.getAttribute("pass"):_pass;
- _error = JSValidator.Tools.Exists(tag.getAttribute("error"))?tag.getAttribute("error"):_error;
- _tips = JSValidator.Tools.Exists(tag.getAttribute("tips"))?tag.getAttribute("tips"):_tips;
- _empty = JSValidator.Tools.Exists(tag.getAttribute("empty"))?tag.getAttribute("empty"):_empty;
- _require = JSValidator.Tools.Exists(tag.getAttribute("require"))?tag.getAttribute("require"):_require;
- _to = JSValidator.Tools.Exists(tag.getAttribute("to"))?tag.getAttribute("to"):_to;
- _as = JSValidator.Tools.Exists(tag.getAttribute("as"))?tag.getAttribute("as"):_as;
- _mode = JSValidator.Tools.Exists(tag.getAttribute("mode"))?tag.getAttribute("mode"):_mode;
- _min =JSValidator.Tools.Exists(tag.getAttribute("min"))?tag.getAttribute("min"):_min;
- _max = JSValidator.Tools.Exists(tag.getAttribute("max"))?tag.getAttribute("max"):_max;
- _enum = JSValidator.Tools.Exists(tag.getAttribute("enum"))?tag.getAttribute("enum"):_enum;
- _except =JSValidator.Tools.Exists(tag.getAttribute("except"))?tag.getAttribute("except"):_except;
- _format = JSValidator.Tools.Exists(tag.getAttribute("format"))?tag.getAttribute("format"):_format;
- _beginwith =JSValidator.Tools.Exists(tag.getAttribute("beginwith"))?tag.getAttribute("beginwith"):_beginwith;
- _endwith =JSValidator.Tools.Exists(tag.getAttribute("endwith"))?tag.getAttribute("endwith"):_endwith;
- _expression =JSValidator.Tools.Exists(tag.getAttribute("expression"))?tag.getAttribute("expression"):_expression;
-
- this.empty = _empty;
- this.tips = _tips;
- this.error = _error;
- this.pass = _pass;
- this.temp = "";
-
- this.limits["min"] = _min;
- this.limits["max"] = _max;
- this.limits["enum"] = _enum;
- this.limits["except"] = _except;
- this.limits["beginwith"] = _beginwith;
- this.limits["endwith"] = _endwith;
- this.limits["format"] = _format;
- //......
- }
- }
- };
-
- /**
- *?? ??????
- **/
- //#---class JSValidator.Tools start--#//
- JSValidator.Tools={
- //?????ID???????
- $:function(id){return document.getElementById(id);},
-
- //???? ?????????
- Exists:function(obj){
- if(typeof(obj)=='undefined'||obj==null){
- return false;
- }else{
- return true;
- }
- },
-
- //????? ???????????
- InsertAfter:function(newElement,targetElement){
- var parent = targetElement.parentNode;
- if(parent.lastChild == targetElement){
- parent.appendChild(newElement);
- }else{
- parent.insertBefore(newElement,targetElement.nextSibling);
- }
- },
-
- //? ??????????? ??
- AddEventFunc:function(obj,eve,func,param){
- var oldfunc = obj[eve];
- if(typeof obj[eve] !='function'){
- obj[eve] = function(event){
- event=window.event||event;
- func(event.srcElement?event.srcElement:event.target,param);
- return JSValidator.validateForm.submit;
- }
- }else{
- obj[eve] = function(event){
- event=window.event||event;
- oldfunc(event.srcElement?event.srcElement:event.target,param);
- func(event.srcElement?event.srcElement:event.target,param);
- return JSValidator.validateForm.submit;
- }
- }
- },
-
- //??? ??????? ?????Date??
- GetDateFromStr:function(dateStr){
- var datetime=null;
- var d = dateStr.split(" ");
- if(d.length>1){
- t = d[1].split(":");
- d = d[0].split("-");
- datetime = new Date(d[0],d[1],d[2],t[0],t[1],t[2]);
- }else{
- d = dateStr.split("-");
- datetime = new Date(d[0],d[1],d[2]);
- }
- return datetime;
- }
- };//#---class JSValidator.Tools end--#//
-
-
- /**
- *??? ?????
- */
- //#---class JSValidator.Core start--#//
- JSValidator.Core={
- /**?? ?????????????????? **/
- validate:function(formElement,operate){
- //?? ???????
- var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
- // ???tag?? ??? Bean
- var Bean = new JSValidator.validateBean();
- Bean.initTag(tag);
-
- //JSValidator.validateForm.submit=true;
- /**** ?? ?????????***/
- // rule?? ??? ????? ?
- if(operate==""){
- // ?? ????? ?????
- if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
- if(Bean.getRequire()=="true"){ //???????
- JSValidator.Message.Show(Bean,"empty");
- JSValidator.validateForm.submit=false;
- }else{ //??? ?????
- JSValidator.Message.Show(Bean,"temp");
- }
- }else if(!(JSValidator.regulation.simple[Bean.getRule()].test(formElement.value))){
- JSValidator.Message.Show(Bean,"error");
- JSValidator.validateForm.submit=false;
- }else{
- JSValidator.Message.Show(Bean,"pass");
- }
- }
- // rule?? ?? ????? ?
- else if(operate=="||"||operate=="&&"){
- var rules = Bean.getRule().split(operate);
-
- var b = false;
- for(var i=0;i<rules.length;i++){
- if(rules[i]!="limit"){ //??? ????
- // ? ?? ??
- if(operate=="||"){
- b = false;
- b = JSValidator.regulation.simple[rules[i]].test(formElement.value)?true:false;
- if(b==true){
- break;
- }
- }
- // ? ?? ??
- else if(operate=="&&"){
- b = true;
- b = JSValidator.regulation.simple[rules[i]].test(formElement.value)?true:false;
- if(b==false){
- break;
- }
- }
- }else{ //??? ???? ? limit ??
- // ? ?? ??
- if(operate=="||"){
- b = false;
- b = JSValidator.regulation.complex.limit(formElement.value,Bean)?true:false;
- alert(b);
- if(b==true){
- break;
- }
- }
- // ? ?? ??
- else if(operate=="&&"){
- b = true;
- b = JSValidator.regulation.complex.limit(formElement.value,Bean)?true:false;
- if(b==false){
- break;
- }
- }
- }
- }
- if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
- if(Bean.getRequire()=="true"){ //???????
- JSValidator.Message.Show(Bean,"empty");
- JSValidator.validateForm.submit=false;
- }else{ //??? ?????
- JSValidator.Message.Show(Bean,"temp");
- }
- }else if(!b){
- JSValidator.Message.Show(Bean,"error");
- JSValidator.validateForm.submit=false;
- }else{
- JSValidator.Message.Show(Bean,"pass");
- }
- }
- },
-
- /**? ???? ????**/
- valForCompare:function(formElement){
- //?? ???????
- var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
- // ???tag?? ??? Bean
- var Bean = new JSValidator.validateBean();
- //JSValidator.validateForm.submit=true;
- Bean.initTag(tag);
- var sourceValue = JSValidator.Tools.$(Bean.getFor()).value;
- var targetValue = JSValidator.Tools.$(Bean.getTo()).value;
-
- if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
- if(Bean.getRequire()=="true"){ //???????
- JSValidator.Message.Show(Bean,"empty");
- JSValidator.validateForm.submit=false;
- }else{ //??? ?????
- JSValidator.Message.Show(Bean,"temp");
- }
- }else if(!(JSValidator.regulation.complex.compare(sourceValue,targetValue,Bean.getAs(),Bean.getMode()))){
- JSValidator.Message.Show(Bean,"error");
- JSValidator.validateForm.submit=false;
- }else{
- JSValidator.Message.Show(Bean,"pass");
- }
- },
-
- /***??????? ????? ?????**/
- valForCustom:function(formElement){
- //?? ???????
- var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
- // ???tag?? ??? Bean
- var Bean = new JSValidator.validateBean();
- Bean.initTag(tag);
- //JSValidator.validateForm.submit=true;
- if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
- if(Bean.getRequire()=="true"){ //???????
- JSValidator.Message.Show(Bean,"empty");
- JSValidator.validateForm.submit=false;
- }else{ //??? ?????
- JSValidator.Message.Show(Bean,"temp");
- }
- }else if(!(JSValidator.regulation.complex.custom(formElement.value,Bean.getExpression()))){
- JSValidator.Message.Show(Bean,"error");
- JSValidator.validateForm.submit=false;
- }else{
- JSValidator.Message.Show(Bean,"pass");
- }
- },
-
- valForLimit:function(formElement){
- //?? ???????
- var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
- // ???tag?? ??? Bean
- var Bean = new JSValidator.validateBean();
- Bean.initTag(tag);
- //JSValidator.validateForm.submit=true;
- if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
- if(Bean.getRequire()=="true"){ //???????
- JSValidator.Message.Show(Bean,"empty");
- JSValidator.validateForm.submit=false;
- }else{ //??? ?????
- JSValidator.Message.Show(Bean,"temp");
- }
- }else if(!(JSValidator.regulation.complex.limit(formElement.value,Bean))){
- JSValidator.Message.Show(Bean,"error");
- JSValidator.validateForm.submit=false;
- }else{
- JSValidator.Message.Show(Bean,"pass");
- }
-
- }
-
- };//#---class JSValidator.Core end--#//
-
- /**
- *??? ???
- */
- JSValidator.Message={
- MsgCss:{
- empty:"msg_error",
- pass:"msg_ok",
- error:"msg_error",
- tips:"msg_tips",
- temp:""
- },
-
- /**?????????
- tagBean - ???????????? (JSValidator.validateBean)
- msgContent-?????????? ??empty,error,pass,tips?,
- **/
- Show:function(tagBean,msgContent){
- var span = null; // span ???
- var spanid = "JSValidator"+tagBean.getFor()+tagBean.getId()+""; // span ????id
- if(JSValidator.Tools.$(spanid)){ // ?? ???????
- span= JSValidator.Tools.$(spanid); // ?? span??
- }else{
- span = document.createElement("span"); // ?? ??????
- span.id= spanid; // ?? id
- JSValidator.Tools.InsertAfter(span,JSValidator.Tools.$(tagBean.getFor())); //??????????????
- }
- span.innerHTML = tagBean[msgContent]!=null? tagBean[msgContent]:""; // ??????
- span.className = this.MsgCss[msgContent]; // ??????
- },
-
- //????????????????????????
- Remove:function(){
-
- }
- };
-
- var ValidateFactory={
- GetValidateField:function(tagItem,iterateCount){
- //??????????? id
- tagItem.setAttribute("id","mytagelement"+iterateCount);
- //??? ??id?? ????????????????
- JSValidator.Tools.$(tagItem.getAttribute("for")).setAttribute("tagid","mytagelement"+iterateCount);
- //??? ?? ??????? ??? Bean
- var formBean = new JSValidator.validateBean();
- formBean.initTag(tagItem);
-
- if(!JSValidator.Tools.Exists(formBean.getRule())){
- throw new Error("????????rule??????");
- return false;
- }
- /**????tips??????? onfocus??**/
- if(JSValidator.Tools.Exists(formBean.getTips())){
- JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onfocus",JSValidator.tipuser,"temp_param");
- }
-
- var s1 = formBean.getRule().indexOf("||");
- var s2 = formBean.getRule().indexOf("&&");
-
-
- /**???? ?????? ? ????? ????**/
- if((s1!=-1)||(s2!=-1)){ //???????????
- if(formBean.getRule().indexOf("compare")!=-1){
- throw new Error("rule??????????'copare'????????????rule????");
- return false;
- }else if(formBean.getRule().indexOf("custom")!=-1){
- throw new Error("rule??????????'custom'????????????rule????");
- return false;
- }else if(s1!=-1&&s2!=-1){
- throw new Error("rule???????????????? ????????rule????");
- return false;
- }else{
- var operate = s1!=-1?"||":"&&"; //?????
- /***????????? ?????? onblur??****/
- JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.validate,operate);
- }
- }
- else{//?? ?? ? ?????? ??
- switch(formBean.getRule()){
- case "limit":
- JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.valForLimit,"");
- break;
- case "compare":
- JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.valForCompare,"");
- break;
- case "custom":
- JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.valForCustom,"");
- break;
- default :
- JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.validate,"");
- break;
- }
- }
- }
-
- };
- /**
- *??????
- */
- JSValidator.Exception=function(message){
- alert(">>???????:\n\t????:"+message);
- };
-
- //-->