()
| 34505 | * </example> |
| 34506 | */ |
| 34507 | var patternDirective = function() { |
| 34508 | return { |
| 34509 | restrict: 'A', |
| 34510 | require: '?ngModel', |
| 34511 | link: function(scope, elm, attr, ctrl) { |
| 34512 | if (!ctrl) return; |
| 34513 | |
| 34514 | var regexp, patternExp = attr.ngPattern || attr.pattern; |
| 34515 | attr.$observe('pattern', function(regex) { |
| 34516 | if (isString(regex) && regex.length > 0) { |
| 34517 | regex = new RegExp('^' + regex + '$'); |
| 34518 | } |
| 34519 | |
| 34520 | if (regex && !regex.test) { |
| 34521 | throw minErr('ngPattern')('noregexp', |
| 34522 | 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp, |
| 34523 | regex, startingTag(elm)); |
| 34524 | } |
| 34525 | |
| 34526 | regexp = regex || undefined; |
| 34527 | ctrl.$validate(); |
| 34528 | }); |
| 34529 | |
| 34530 | ctrl.$validators.pattern = function(modelValue, viewValue) { |
| 34531 | // HTML5 pattern constraint validates the input value, so we validate the viewValue |
| 34532 | return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue); |
| 34533 | }; |
| 34534 | } |
| 34535 | }; |
| 34536 | }; |
| 34537 | |
| 34538 | /** |
| 34539 | * @ngdoc directive |
nothing calls this directly
no test coverage detected