var pattern=new RegExp("^[\\d]{"+minLength+","+maxLength+"}","g");g---代表全局匹配.

解决方案 »

  1.   

    function isNumberxxx(handle,minLength,maxLength)
    {
     if(handle.value.length<=0)
       return false;  var pattern = new RegExp("^[\\d]{"+minLength+","+maxLength+"}","g");  if(!pattern.exec(handle.value)) 
       {
          window.alert("输入有误,请输入长度在"+minLength+"到"+maxLength+"的数字");
          handle.focus();
          handle.select();
          return false;
       }
       else
        return true;
     
    }
    当输入参数为min:3 max:5 界面上输入长度小于3的正常,但大于5时却没有报错,请指教
      

  2.   

    是否pattern.exec返回的数组中包含了数值,所以认为是不为null
    这样的话,我就不能限制它的最大值了
      

  3.   

    function isNumberxxx(handle,minLength,maxLength)
    {
     if(handle.value.length<=0)
       return false;   var pattern = new RegExp("^[\\d]{"+minLength+","+maxLength+"}","g");
       var result=handle.value.toString().match(pattern );
       if(result!=null)--如果匹配的话就会有结果返回,而且有多个结果返回的话则自动用逗号(,)分开;
       {
          return true;
       }
       else
       {
          window.alert("输入有误,请输入长度在"+minLength+"到"+maxLength+"的数字");
          handle.focus();
          handle.select();
          return false;
       }
    }