()
| 32256 | * </example> |
| 32257 | */ |
| 32258 | var patternDirective = function() { |
| 32259 | return { |
| 32260 | restrict: 'A', |
| 32261 | require: '?ngModel', |
| 32262 | link: function(scope, elm, attr, ctrl) { |
| 32263 | if (!ctrl) return; |
| 32264 | |
| 32265 | var regexp, patternExp = attr.ngPattern || attr.pattern; |
| 32266 | attr.$observe('pattern', function(regex) { |
| 32267 | if (isString(regex) && regex.length > 0) { |
| 32268 | regex = new RegExp('^' + regex + '$'); |
| 32269 | } |
| 32270 | |
| 32271 | if (regex && !regex.test) { |
| 32272 | throw minErr('ngPattern')('noregexp', |
| 32273 | 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp, |
| 32274 | regex, startingTag(elm)); |
| 32275 | } |
| 32276 | |
| 32277 | regexp = regex || undefined; |
| 32278 | ctrl.$validate(); |
| 32279 | }); |
| 32280 | |
| 32281 | ctrl.$validators.pattern = function(modelValue, viewValue) { |
| 32282 | // HTML5 pattern constraint validates the input value, so we validate the viewValue |
| 32283 | return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue); |
| 32284 | }; |
| 32285 | } |
| 32286 | }; |
| 32287 | }; |
| 32288 | |
| 32289 | /** |
| 32290 | * @ngdoc directive |
nothing calls this directly
no test coverage detected