Hike Nalbandyan
Hike Nalbandyan

Reputation: 1056

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.

Upvotes: 12

Views: 8637

Answers (1)

Parag Bhayani
Parag Bhayani

Reputation: 3330

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" />

Upvotes: 38

Related Questions