Jq validate 양식 유효성 검사 플러그인 사용자 정의 유효성 검사 규칙

3942 단어
//우편번호 확인
jQuery.validator.addMethod( "checkPost",function(value,element){       

        var pattern =/^[0-9]{6}$/;    

        if(value !=''){if(!pattern.exec(value)){return false;}};    

        return true;     

 } ,  "          ");       

 //          

jQuery.validator.ddMethod("toLowerCase",function(value,element) {value = $.trim(String(value));//비우기if(value="){element.value =";return this.optional(element)|true;}if(value.toLowerCase()!=value) element.value = value.toLowerCase(); return this.optional(element)|| true; }, "");
//        

jQuery.validator.addMethod( "checkMobile",function(value,element){       

     var reg0 = /^13\d{5,9}$/;    

     var reg1 = /^15\d{5,9}$/;    

     var reg2 = /^189\d{4,8}$/;    

     var reg3 = /^0\d{10,11}$/;    

     var my = false;    

     if (reg0.test(value))my=true;    

     if (reg1.test(value))my=true;    

     if (reg2.test(value))my=true;    

     if (reg3.test(value))my=true;    

     if(value!=''){if(!my){return false;}};    

    return true;     

 } ,  "           );       

  //     6-18                  ..  

jQuery.validator.addMethod("checkPassword",function(value, element) {  
      var myreg = /^[^\s]{6,18}$/;  
      if (value != '') {if (!myreg.test(value)) {return false;}};  
      return true;}, "       !");     

//        

jQuery.validator.addMethod( "checkEmail",function(value,element){       

        var myreg = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;  

        if(value !=''){if(!myreg.test(value)){return false;}};    

        return true;     

 } ,  "       E_mail");     



//          

jQuery.validator.addMethod( "checkTel",function(value,element){       

    var pattern =/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;    

    if(value!=''){if(!pattern.exec(value)){return false;}};    

    return true;     

} ,  "          ");        

     

    

//            

jQuery.validator.addMethod( "checkName",function(value,element){       

    var returnMsg=true;    

    jQuery.ajax({type:"get",url:"url",    

    async:false,cache:false,data:{ toinName:value,method:"get"},dataType:"html",scriptCharset:"UTF-8",success:function(msg){    

        if(msg=="1"){    

            returnMsg=false;    

        }    

    }});    

    return returnMsg;    

} ,  "        !        ");        

    

$("#addForm").validate({    

    errorPlacement:function (error, element){       

        if(element.attr("type")=="checkbox"||element.attr("type")=="radio"){    

            error.appendTo(element.parent());    

        }else{    

            error.appendTo(element.parent());    

        }           

    },    

    rules: {    

        toinCompanyName:{    

            required: true,    

            checkCompanyName:true    

        },usinName:{    

            required: true    

        },usinSex:{    

            required: true    

        },usinZw:{    

            required: true    

        },toinCatalogId:{    

            required: true    

        },usinCounty:{    

            required: true    

        },usinQicq:{    

            number: true    

        },toinCompanyIntroduction:{    

            maxlength:400    

        },usinEmail:{    

            checkEmail:true  ,  

           toLowerCase:true  

        },usinTel:{    

            checkTel : true    

        },usinMobile:{    

            checkMobile : true    

        },usinPost :{    

            checkPost : true    

        }    

    },    

    messages: { .... }    

});   

html 가입class 가져오기
출처:http://huqiji.iteye.com/blog/2166986

좋은 웹페이지 즐겨찾기