title: Directive order in angularjs form validations
body: <p>I have a custom directive which validates the field and on the same field I have applied ng-pattern for checking whether the input is number or not. The problem I am facing is that the custom directive always runs before ng-pattern.</p>
  
  <p>Desired Behavior-
  ng-pattern->customValidator</p>
  
  <p>Right now its-
  customValidator->ng-pattern</p>
  
  <p>I have not specified any prioriry on customValidator and also don't want to.
  Is there any way that I can force this custom-validator to run after ng-pattern.</p>
  
  <pre><code>&lt;input type=text ng-pattern="/^[1-9][0-9]*$/" customValidator&gt;
  
  .directive('customValidator', function () {
          return {
              restrict: 'A',
              require: 'ngModel',
              link: function (scope, elem, attrs, ngModel) {
                  ngModel.$parsers.unshift(validate);
  
                  scope.$watch(ngModel.$viewValue, function () {
                      ngModel.$setViewValue(ngModel.$viewValue);
                  });
  
                  function validate(value) {
                      // validation code
                      if (validation) {
                         ngModel.$setValidity('custom', true);
                         return value;
                      }
                      else {
                         ngModel.$setValidity('custom', false);
                         return false;
                      }                  
                  }
              }
          };
      })
  </code></pre>