var Filters = Filters || {}; angular.extend(Filters, { mobile: function (value) { if (angular.isUndefined(value)) { return ''; } var value = "" + value; value = value.replace(/[-\s]/, ''); if (value.length === 9) { value = '+48' + value; } var matches = value.match(/^(\+\d{2})(\d{3})(\d{3})(\d{3})$/); if (matches && matches.length > 0) { matches.shift(); //var d = matches.shift(); value = /*d + ' ' + */matches.join(' '); } return value; } }); app.filter('mobile', function () { return Filters.mobile; });