/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Array de objectos de qual caracter deve substituir seu par com acentos */ var specialChars = [ {val:"a",let:"áà ãâä"}, {val:"e",let:"éèêë"}, {val:"i",let:"Ãìîï"}, {val:"o",let:"óòõôö"}, {val:"u",let:"úùûü"}, {val:"c",let:"ç"}, {val:"A",let:"ÃÀÃÂÄ"}, {val:"E",let:"ÉÈÊË"}, {val:"I",let:"ÃÌÎÃ"}, {val:"O",let:"ÓÒÕÔÖ"}, {val:"U",let:"ÚÙÛÜ"}, {val:"C",let:"Ç"}, {val:"",let:"?!()"} ]; /** * Função para substituir caractesres especiais. * @param {str} string * @return String */ function replaceSpecialChars(str) { var $spaceSymbol = '-'; var regex; var returnString = str; for (var i = 0; i < specialChars.length; i++) { regex = new RegExp("["+specialChars[i].let+"]", "g"); returnString = returnString.replace(regex, specialChars[i].val); regex = null; } return returnString.replace(/\s/g,$spaceSymbol); };