Detect if string is (mostly) Arabic (or Farsi, etc.)
function detectArabic(string) {
try {
arCount = string.match(/[\u0600-\u06FF]/g).length;
// results are approximative because whitespace and some ranges of arabic characters are ignored.
return((string.length / arCount) > .5);
} catch(e) {
return(false);
}
}
// to use on HTML element "el":
// detectArabic(el.innerText)