title: How to set an input field to ng-invalid in angularJS
body: <p>I would like to check an input field for credit card numbers.</p>
  
  <p>The field should remain invalid until it has a minimum length of 13. As the user should be able to fill in space into the field, I remove those spaces within a javascript function.
  In this function I would like to check the credit card number (without spaces) and set it to ng-invalid as long as the minimum length is lesser than 13 and the maximum length is greater than 16.</p>
  
  <p>It should be something like this:</p>
  
  <pre><code>$scope.ccHandler = function() {
     if ($scope.ccNumber == '') {
        document.getElementById("ccProvider").disabled = false;
     }
     $scope.ccNumber = inputCC.value.split(' ').join(''); //entfernt die Leerzeichen aus der Kreditkartennummer vor der übergabe an den Server
     console.log("das ist meine CC: " + $scope.ccNumber);
     isValidCreditCardNumber($scope.ccNumber);
     getCreditCardProvider($scope.ccNumber);
     document.getElementById("ccProvider").disabled = true;
     if ($scope.ccNumber.length &lt; creditCardNumberMinLength || $scope.ccNumber.length &gt; creditCardNumberMaxLength) {
        //$scope.ccNumber.ng-invalid = true;
        console.log("ccNumber ist noch ungültig!");
        //document.getElementById("inputCC").$setValidity("ccNumber", false);
     }
  }
  </code></pre>
  
  <p>This would be the part of the XHTML:</p>
  
  <pre><code>&lt;div class="form-group" ng-switch-when="CreditCard"&gt;
     &lt;label class="col-xs-3 col-sm-3 control-label"&gt;Kreditkartennummer&lt;/label&gt; 
     &lt;div class="col-xs-5 col-sm-5 col-md-5"&gt;
        &lt;input name="ccNumber" class="form-control" type="text" id="inputCC" ng-change="ccHandler();updateCount()" ng-model="ccNumber" ng-required="true"/&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>How can I achieve this?</p>