title: angularjs validate input and prevent change if invalid
body: <p>I neeed an input field where I can enter only the values 1,2 or 3 so i'm trying to build a directive which prevents all changes to the model if it doesn't match these values.<br>
  eg the value is 1 and I change it to 5 it should be still 1.</p>
  
  <p>I've put together a small fiddle <a href="http://jsfiddle.net/kannix/Q5YKE/" rel="nofollow">http://jsfiddle.net/kannix/Q5YKE/</a> but it's most likely wrong to use the $parsers.</p>
  
  <pre><code>app.directive('myvalidator', function () {
      return {
          require: 'ngModel',
          link: function (scope, elm, attrs, ctrl) {
              var validValues = [1,2,3];
              ctrl.$parsers.push(function (value) {
                  if (validValues.indexOf(value) === -1){
                      //what to do here? should refuse wrong value and leave the old one
                  }   
              });
          }
      }   
  
  })
  </code></pre>