Skip to content

Instantly share code, notes, and snippets.

@phanletrunghieu
Forked from hu2di/ConvertVie.js
Created April 18, 2019 06:17
Show Gist options
  • Save phanletrunghieu/0b7495c907afec09bc507997fb13c6a3 to your computer and use it in GitHub Desktop.
Save phanletrunghieu/0b7495c907afec09bc507997fb13c6a3 to your computer and use it in GitHub Desktop.
JavaScript: Chuyển tiếng Việt có dấu sang không dấu
function change_alias(alias) {
var str = alias;
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");
str = str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'|\"|\&|\#|\[|\]|~|\$|_|`|-|{|}|\||\\/g," ");
str = str.replace(/ + /g," ");
str = str.trim();
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment