()
| 29487 | * </example> |
| 29488 | */ |
| 29489 | var patternDirective = function() { |
| 29490 | return { |
| 29491 | restrict: 'A', |
| 29492 | require: '?ngModel', |
| 29493 | link: function(scope, elm, attr, ctrl) { |
| 29494 | if (!ctrl) return; |
| 29495 | |
| 29496 | var regexp, patternExp = attr.ngPattern || attr.pattern; |
| 29497 | attr.$observe('pattern', function(regex) { |
| 29498 | if (isString(regex) && regex.length > 0) { |
| 29499 | regex = new RegExp('^' + regex + '$'); |
| 29500 | } |
| 29501 | |
| 29502 | if (regex && !regex.test) { |
| 29503 | throw minErr('ngPattern')('noregexp', |
| 29504 | 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp, |
| 29505 | regex, startingTag(elm)); |
| 29506 | } |
| 29507 | |
| 29508 | regexp = regex || undefined; |
| 29509 | ctrl.$validate(); |
| 29510 | }); |
| 29511 | |
| 29512 | ctrl.$validators.pattern = function(modelValue, viewValue) { |
| 29513 | // HTML5 pattern constraint validates the input value, so we validate the viewValue |
| 29514 | return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue); |
| 29515 | }; |
| 29516 | } |
| 29517 | }; |
| 29518 | }; |
| 29519 | |
| 29520 | /** |
| 29521 | * @ngdoc directive |
nothing calls this directly
no test coverage detected