title: preventing maxLength on a input type number
body: <p>I took me a while to figure this one out, but can someone post a cleaner method for limiting the number of digits in an input type='number'.  One of the issues is that errors are thrown if $scope.variable = null....meaning nothing in the input field.</p>
  
  <pre><code>&lt;input type="number" model='modalName' ng-change="monitorLength('modalName',16)"&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>  $scope.monitorLength = function (model,maxLength) {
      if ($scope[model] != null) {  // prevent error on empty input field
        var len = $scope[model].toString() ;  // convert to a string
        if (len.length &gt; maxLength) {  //evaluate string length
          $scope[model] = parseInt(len.substring(0, maxLength));  
          // convert back to number or warning is thrown on input value not being a number
        }
      }
    }
  </code></pre>
  
  <p>I then needed to expand up on this to account for number only, preventing any non-digit characters include '.' and ',' symbols:</p>
  
  <pre><code>  var reg = new RegExp(/^\d+$/) ;
    $scope.monitorLength = function (modal,maxLength) {
      if ($scope[modal] != null) {
        var len = $scope[modal].toString() ;
        if (len.length &gt; maxLength) {
          $scope[modal] = parseInt(len.substring(0, maxLength));
        } else if (!reg.test(len)) {
          $scope[modal] = parseInt(len.substring(0, len.length-2));
        }
      }
    }  
  </code></pre>
  
  <p>Is there way to extract the ng-modal that was responsible for calling the ng-change?  so the call would only have to be: <code>ng-change="monitorLength(10)"</code>.  And then in the function somehow dynamically retrieve the calling ng-modal?</p>