How to check if a string contains characters in Hebrew in JavaScript

1 Answer

0 votes
const HebrewUnicodeBlock = /[\u0590-\u05FF]/; // Hebrew, Yiddish, Ladino (112 code points)
 
const str1 = "שלוםhello";
if (HebrewUnicodeBlock.test(str1)) {
    console.log("The string contains Hebrew characters.");
} else {
    console.log("The string does not contain Hebrew characters.");
}
 
const str2 = "שלום";
if (HebrewUnicodeBlock.test(str2)) {
    console.log("The string contains Hebrew characters.");
} else {
    console.log("The string does not contain Hebrew characters.");
}
 
const str3 = "hello";
if (HebrewUnicodeBlock.test(str3)) {
    console.log("The string contains Hebrew characters.");
} else {
    console.log("The string does not contain Hebrew characters.");
}
 
 
 
/*
run:
 
The string contains Hebrew characters.
The string contains Hebrew characters.
The string does not contain Hebrew characters.
 
*/

 



answered Nov 7, 2024 by avibootz
edited Nov 7, 2024 by avibootz
...