The following code shows how to use filter to remove space and lowercase with regular expression.
<!-- w ww . j a va2 s .co m-->
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
<script type='text/javascript'>
var filterExample = angular.module('example',[]);
filterExample.filter('removeSpacesThenLowercase', function () {
return function (text) {
var str = text.replace(/\s+/g, '');
return str.toLowerCase();
};
})
function Ctrl($scope) {
$scope.names = ['Santi Carzola','Theo Walcott','Oliver Giroud','Jack Wilshere']
}
</script>
</head>
<body>
<div ng-app="example">
<div ng-controller="Ctrl">
<p ng-repeat="name in names">{{name}} = {{name | removeSpacesThenLowercase}}</p>
</div>
</div>
</body>
</html>
The code above is rendered as follows: