Skip to content

Instantly share code, notes, and snippets.

@gerisztein
Created September 22, 2014 18:29
Show Gist options
  • Save gerisztein/d21f016630957cc20d43 to your computer and use it in GitHub Desktop.
Save gerisztein/d21f016630957cc20d43 to your computer and use it in GitHub Desktop.
Capitalize filter for AngularJS
(function() {
'use strict';
angular.module('capitalize', [])
.filter('capitalize', function() {
return function(str) {
return (!!str) ? str.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}) : '';
};
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment