11

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.

Hike Nalbandyan
  • 994
  • 1
  • 11
  • 28

1 Answers1

35

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" />
LWC
  • 1,084
  • 1
  • 10
  • 28
Parag Bhayani
  • 3,280
  • 2
  • 28
  • 52