()
| 33816 | * </example> |
| 33817 | */ |
| 33818 | var patternDirective = function() { |
| 33819 | return { |
| 33820 | restrict: 'A', |
| 33821 | require: '?ngModel', |
| 33822 | link: function(scope, elm, attr, ctrl) { |
| 33823 | if (!ctrl) return; |
| 33824 | |
| 33825 | var regexp, patternExp = attr.ngPattern || attr.pattern; |
| 33826 | attr.$observe('pattern', function(regex) { |
| 33827 | if (isString(regex) && regex.length > 0) { |
| 33828 | regex = new RegExp('^' + regex + '$'); |
| 33829 | } |
| 33830 | |
| 33831 | if (regex && !regex.test) { |
| 33832 | throw minErr('ngPattern')('noregexp', |
| 33833 | 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp, |
| 33834 | regex, startingTag(elm)); |
| 33835 | } |
| 33836 | |
| 33837 | regexp = regex || undefined; |
| 33838 | ctrl.$validate(); |
| 33839 | }); |
| 33840 | |
| 33841 | ctrl.$validators.pattern = function(modelValue, viewValue) { |
| 33842 | // HTML5 pattern constraint validates the input value, so we validate the viewValue |
| 33843 | return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue); |
| 33844 | }; |
| 33845 | } |
| 33846 | }; |
| 33847 | }; |
| 33848 | |
| 33849 | /** |
| 33850 | * @ngdoc directive |
nothing calls this directly
no test coverage detected