Skip to content

Instantly share code, notes, and snippets.

@wholypantalones
Created July 20, 2015 13:53
Show Gist options
  • Save wholypantalones/ef497363f42152f3abc1 to your computer and use it in GitHub Desktop.
Save wholypantalones/ef497363f42152f3abc1 to your computer and use it in GitHub Desktop.
Capitalized AlphaNumeric Directive
.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