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

Function patternDirective

test/angular/1.4/angular.js:29489–29518  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29487 * </example>
29488 */
29489var 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

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