天天看点

简单的验证

页面字段比较多 ,自己写了一个简单的页面验证

var myinput2=new Array("enter_name:企业/个体工商户名称:C:*",
      "enter_operator:经营者/法人:C:*",
      "enter_uscc:注册号/统一社会信用代码:C:*",
      "enter_register_time:企业/门店注册时间:C:*",
     // "enter_address:企业/门店地址:C",
      "enter_area:企业/门店面积(平米):M:*",
      "enter_brand:经营品牌:C:*",
      "enter_period:经营年限:N:5",
      "enter_tm_amount:近三月销售总额(元):M:*",
      "enter_tm_aveamount:近三月月均销售额(元):M:*",
      "enter_ly_amount:上年度销售总额(元):M:*",
      "enter_ly_profit:上年度利润(元):M:*",
      "enter_stock_value:库存总价值(元):M:*",
      "enter_gp_value:门店黄铂金总价值(元):M:*",
      "optEmploye:员工人数:N:*"
)  

    function isgotoc(e){
      for (x in e)
      {
          var str=e[x].split(":");
          var  number=$.trim($("#"+str[]).val());
          if( number==""||number==null||(typeof number == undefined)){
                    layer.alert(str[]+"不能为空!");
                    return false;
          } 
          if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='N'){
              var reg = /^[1-9]\d*$/;
              if(!reg.test(number) ){
                    layer.alert(str[]+"格式不正确!");
                    return false;
                }
             }

          if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='M'){
              var reg = /(?!0\.00)(\d+\.\d{0,2}$)/;
              var reg1 = /^[1-9]\d*$/;
              if(!(reg.test(number)||reg1.test(number)) ){
                    layer.alert(str[]+"格式不正确!");
                    return false;
                }

             }
          if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='P'){
              var reg = new RegExp("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$");
                if (!reg.test(number)) {
                    layer.alert(str[]+"格式不正确!");
                    return false;
                }
         }  
          if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='T'){
              var reg =  new RegExp("^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$");
                if (!reg.test(number)) {
                    layer.alert(str[]+"格式不正确!");
                    return false;
                }
         }  
          if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='TP'){
              var reg1 = new RegExp("^((13[0-9])|(14[0-9])|(15([0-9]))|(18[0-9])|(17[0-9]))\\d{8}$");
              var reg2 = new RegExp("^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$");
                if (!(reg1.test(number)||reg2.test(number))) {
                    layer.alert(str[]+"格式不正确!");
                    return false;
                }
         }  


          if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='ID'){
              var reg=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/; 

                if (!reg.test(number)) {
                    layer.alert(str[]+"格式不正确!");
                    return false;
                }
         }
         if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]!='*'){
              if(number.length>str[]){
                  layer.alert(str[]+"字符长度不能超过"+ str[]);
                    return false;
              }
         }  
      }


      return true;
  }