Filter to remove space and lowercase with regular expression

Description

The following code shows how to use filter to remove space and lowercase with regular expression.

Example


<!-- w  ww  . ja  v  a2 s  . c om-->
<!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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities