()
| 34728 | * </example> |
| 34729 | */ |
| 34730 | var patternDirective = function() { |
| 34731 | return { |
| 34732 | restrict: 'A', |
| 34733 | require: '?ngModel', |
| 34734 | link: function(scope, elm, attr, ctrl) { |
| 34735 | if (!ctrl) return; |
| 34736 | |
| 34737 | var regexp, patternExp = attr.ngPattern || attr.pattern; |
| 34738 | attr.$observe('pattern', function(regex) { |
| 34739 | if (isString(regex) && regex.length > 0) { |
| 34740 | regex = new RegExp('^' + regex + '$'); |
| 34741 | } |
| 34742 | |
| 34743 | if (regex && !regex.test) { |
| 34744 | throw minErr('ngPattern')('noregexp', |
| 34745 | 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp, |
| 34746 | regex, startingTag(elm)); |
| 34747 | } |
| 34748 | |
| 34749 | regexp = regex || undefined; |
| 34750 | ctrl.$validate(); |
| 34751 | }); |
| 34752 | |
| 34753 | ctrl.$validators.pattern = function(modelValue, viewValue) { |
| 34754 | // HTML5 pattern constraint validates the input value, so we validate the viewValue |
| 34755 | return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue); |
| 34756 | }; |
| 34757 | } |
| 34758 | }; |
| 34759 | }; |
| 34760 | |
| 34761 | /** |
| 34762 | * @ngdoc directive |
nothing calls this directly
no test coverage detected