Skip to content

Instantly share code, notes, and snippets.

@cuduy197
Created September 11, 2017 18:10
Show Gist options
  • Save cuduy197/ae713f898d4664987fdceca8435ea7c8 to your computer and use it in GitHub Desktop.
Save cuduy197/ae713f898d4664987fdceca8435ea7c8 to your computer and use it in GitHub Desktop.
Bỏ dấu tiếng việt
function bodau(str,isLowerCase, isUnderLine) {
if(isLowerCase) {str = str.toLowerCase()}
str = str.replace(/à|á|||ã|â||||||ă|||||/g, 'a');
str = str.replace(/è|é||||ê||ế|||/g, 'e');
str = str.replace(/ì|í|||ĩ/g, 'i');
str = str.replace(/ò|ó|||õ|ô||||||ơ|||||/g, 'o');
str = str.replace(/ù|ú|||ũ|ư|||||/g, 'u');
str = str.replace(/|ý|||/g, 'y');
str = str.replace(/đ/g, 'd');
if(isUnderLine) {
str = str.replace(/\W+/g, ' ');
str = str.replace(/\s/g, '-');
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment