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

Function patternDirective

test/angular/1.6/angular.js:34507–34536  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34505 * </example>
34506 */
34507var 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

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