user14118739
user14118739

Reputation: 11

ng-pattern does not work when pattern set dynamically in ng-repeat

I have some sets of patterns in my controller. I am trying to set this pattern dynamically for ng-pattern using ng-repeat.

Pattern example :

$scope.codePattern = (function () {
  var regexp = /^([a-zA-Z0-9_]+){2,}$/;
  return {
    test(value) {
      return regexp.test(value);
    },
  };
})();

This pattern name is stored in DB and is assigned to ng-pattern in ng-repeat. But somehow this is not working. However, when I hard-code it works perfectly.

Upvotes: 1

Views: 47

Answers (0)

Related Questions