Skip to content

Instantly share code, notes, and snippets.

@thanhnguyen2187
Created July 26, 2025 15:37
Show Gist options
  • Save thanhnguyen2187/0979831f63fd52e533c36174bfe19171 to your computer and use it in GitHub Desktop.
Save thanhnguyen2187/0979831f63fd52e533c36174bfe19171 to your computer and use it in GitHub Desktop.
A naive algorithm to detect if the input text is Vietnamese
const specialChars = `
á à ả ã ạ
ă ắ ằ ẳ ẵ ặ
â ấ ầ ẩ ẫ ậ
ó ò ỏ õ ọ
ơ ớ ờ ở ỡ ợ
ô ố ồ ổ ỗ ộ
ú ù ủ ũ ụ
ư ứ ừ ử ữ ự
í ì ỉ ĩ ị
ý ỳ ỷ ỹ ỵ
é è ẻ ẽ ẹ
ê ế ề ể ễ ệ
`
.trim()
.replace(/\s+/g, "");
const specialCharsRegex = new RegExp(`[${specialChars}]`);
export function isVietnamese(text: string): boolean {
return !!text.match(specialCharsRegex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment