MCPcopy Index your code
hub / github.com/angular-ui/ui-router / patternDirective

Function patternDirective

test/angular/1.5/angular.js:32258–32287  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32256 * </example>
32257 */
32258var 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

Callers

nothing calls this directly

Calls 4

isStringFunction · 0.70
minErrFunction · 0.70
startingTagFunction · 0.70
isUndefinedFunction · 0.70

Tested by

no test coverage detected