Created
July 26, 2025 15:37
-
-
Save thanhnguyen2187/0979831f63fd52e533c36174bfe19171 to your computer and use it in GitHub Desktop.
A naive algorithm to detect if the input text is Vietnamese
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
| 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