()
| 30065 | * </example> |
| 30066 | */ |
| 30067 | var patternDirective = function() { |
| 30068 | return { |
| 30069 | restrict: 'A', |
| 30070 | require: '?ngModel', |
| 30071 | link: function(scope, elm, attr, ctrl) { |
| 30072 | if (!ctrl) return; |
| 30073 | |
| 30074 | var regexp, patternExp = attr.ngPattern || attr.pattern; |
| 30075 | attr.$observe('pattern', function(regex) { |
| 30076 | if (isString(regex) && regex.length > 0) { |
| 30077 | regex = new RegExp('^' + regex + '$'); |
| 30078 | } |
| 30079 | |
| 30080 | if (regex && !regex.test) { |
| 30081 | throw minErr('ngPattern')('noregexp', |
| 30082 | 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp, |
| 30083 | regex, startingTag(elm)); |
| 30084 | } |
| 30085 | |
| 30086 | regexp = regex || undefined; |
| 30087 | ctrl.$validate(); |
| 30088 | }); |
| 30089 | |
| 30090 | ctrl.$validators.pattern = function(modelValue, viewValue) { |
| 30091 | // HTML5 pattern constraint validates the input value, so we validate the viewValue |
| 30092 | return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue); |
| 30093 | }; |
| 30094 | } |
| 30095 | }; |
| 30096 | }; |
| 30097 | |
| 30098 | /** |
| 30099 | * @ngdoc directive |
nothing calls this directly
no test coverage detected