Created
July 20, 2015 13:53
-
-
Save wholypantalones/ef497363f42152f3abc1 to your computer and use it in GitHub Desktop.
Capitalized AlphaNumeric Directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.directive('onlyAlpha', function(){ | |
return { | |
require: 'ngModel', | |
link: function(scope, element, attrs, modelCtrl) { | |
modelCtrl.$parsers.push(function (inputValue) { | |
if (inputValue == undefined) return ''; | |
var transformedInput = inputValue.replace(/[\W_]+/g,'').toUpperCase(); | |
if (transformedInput!=inputValue) { | |
modelCtrl.$setViewValue(transformedInput); | |
modelCtrl.$render(); | |
} | |
return transformedInput; | |
}); | |
} | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment