Last active
December 25, 2015 10:25
-
-
Save giautm/ef54fef9fab275e687e1 to your computer and use it in GitHub Desktop.
Loại bỏ dấu tiếng Việt, nguồn: mp3.zing.vn
This file contains hidden or 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
String.prototype.stripViet = function () { | |
var viet = [ | |
{char: 'a', regex: 'á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ'}, | |
{char: 'o', regex: 'ó|ò|ỏ|õ|ọ|ơ|ớ|ờ|ở|ỡ|ợ|ô|ố|ồ|ổ|ỗ|ộ'}, | |
{char: 'e', regex: 'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ'}, | |
{char: 'u', regex: 'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự'}, | |
{char: 'i', regex: 'í|ì|ỉ|ĩ|ị'}, | |
{char: 'y', regex: 'ý|ỳ|ỷ|ỹ|ỵ'}, | |
{char: 'd', regex: 'đ|ð'} | |
]; | |
var str = this; | |
for (var cas of viet) { | |
str = str.replace(new RegExp(cas.regex, 'g'), cas.char); | |
str = str.replace(new RegExp(cas.regex.toUpperCase(), 'g'), cas.char.toUpperCase()); | |
} | |
return str | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment