MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / patternDirective

Function patternDirective

web/static/bower_components/angular/angular.js:28687–28716  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28685
28686
28687var patternDirective = function() {
28688 return {
28689 restrict: 'A',
28690 require: '?ngModel',
28691 link: function(scope, elm, attr, ctrl) {
28692 if (!ctrl) return;
28693
28694 var regexp, patternExp = attr.ngPattern || attr.pattern;
28695 attr.$observe('pattern', function(regex) {
28696 if (isString(regex) && regex.length > 0) {
28697 regex = new RegExp('^' + regex + '$');
28698 }
28699
28700 if (regex && !regex.test) {
28701 throw minErr('ngPattern')('noregexp',
28702 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp,
28703 regex, startingTag(elm));
28704 }
28705
28706 regexp = regex || undefined;
28707 ctrl.$validate();
28708 });
28709
28710 ctrl.$validators.pattern = function(modelValue, viewValue) {
28711 // HTML5 pattern constraint validates the input value, so we validate the viewValue
28712 return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue);
28713 };
28714 }
28715 };
28716};
28717
28718
28719var maxlengthDirective = function() {

Callers

nothing calls this directly

Calls 4

isStringFunction · 0.85
minErrFunction · 0.85
startingTagFunction · 0.85
isUndefinedFunction · 0.85

Tested by

no test coverage detected