This could be done using the event
onkeydown
. However, I don't recommend doing it because you need to use event structure to solve this problem; and this creates a browser-compatibility problem. However, this problem can be worked around. Please see:
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onkeydown[
^].
Due to this problem, I would recommend using jQuery, which is designed with compatibility in mind. Such problems are already resolved transparently to the users of this library. Please see:
http://en.wikipedia.org/wiki/JQuery[
^],
http://jquery.com/[
^].
Here is the code sample for the solution:
$("#txt").keydown(function(event) {
if ((event.key >= 'א') & (event.key <= 'פֿ'))
alert("Sholom!");
});
(Sorry, I might have messed up with Hebrew characters, because they are hard-to enter because of mixture of left-to-right and right-to-left code and because I don't quite understand how to take into account the conditions on diacritical marks and ligatures, but I hope you got the idea: to write conditions for valid range of Unicode code points.)
—SA