Created
June 28, 2017 00:42
-
-
Save neysimoes/53c7ece0850c9b98380619c4ed2e583d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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