A string is a sequence of characters, each of which has a character code. ASCII defines characters from 0 to 127, so if a character in a string has a code other than this, then it is a Unicode character. This function checks this. See String # charCodeAt .
function hasUnicode (str) {
for (var i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 127) return true;
}
return false;
}
Then use it like hasUnicode("Xin chào tất cả mọi người")
source
share