Skip to content

Instantly share code, notes, and snippets.

@neysimoes
Created June 28, 2017 00:42
Show Gist options
  • Save neysimoes/53c7ece0850c9b98380619c4ed2e583d to your computer and use it in GitHub Desktop.
Save neysimoes/53c7ece0850c9b98380619c4ed2e583d to your computer and use it in GitHub Desktop.
(function() {
'use strict';
angular
.module('app')
.filter('telephone', telephone)
.filter('cpf', cpf)
.filter('cep', cep);
function telephone() {
return function(str) {
if (!str) return;
return str.replace(/^\+55\s?/, '');
};
}
function cpf() {
return function(str) {
str = (str || '')
.replace(/\D/g,'')
.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$4');
return str;
};
}
function cep() {
return function(str) {
str = (str || '')
.replace(/\D/g, '')
.replace(/(\d{5})/, '$1-');
return str;
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment