Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect Hebrew characters in a string in javascript

I'm trying to implement a simple function of detecting whether a string contains Hebrew characters using js. HELP!

Edit: I'm not interested in detecting a rtl language, just Hebrew.

like image 298
Hike Nalbandyan Avatar asked May 22 '16 07:05

Hike Nalbandyan


1 Answers

you need to use this regular expression to search in your string ."/[\u0590-\u05FF]/" i.e.

function contains_heb(str) {
    return (/[\u0590-\u05FF]/).test(str);
}
<input id="the_text" type="text" value="בדיקה" />
<br /><button onclick="document.getElementById('the_output').value = contains_heb(document.getElementById('the_text').value)">Does it contain Hebrew?</button>
<br /><br />
Output:
<br /><input id="the_output" type="text" />
like image 189
Parag Bhayani Avatar answered Oct 15 '22 10:10

Parag Bhayani