Last active
February 2, 2018 17:26
-
-
Save fabiofdsantos/12ef1b66061ab363a1fa to your computer and use it in GitHub Desktop.
An angularJS function to remove accents from an input string.
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 removeAccents (str) { | |
map = { | |
'a' : 'á|à|ã|â|À|Á|Ã|Â', | |
'e' : 'é|è|ê|É|È|Ê', | |
'i' : 'í|ì|î', | |
'o' : 'ó|ò|ô|õ|Ó|Ò|Ô|Õ', | |
'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü', | |
'c' : 'ç|Ç', | |
'n' : 'ñ|Ñ' | |
}; | |
angular.forEach(map, function (pattern, newValue) { | |
str = str.replace(new RegExp(pattern, 'g'), newValue); | |
}); | |
return str; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment