What I said and what you wish I'd said,
may not be the same. Please quote the former.
"Peter" <pv*@speakeasy.net> wrote in message
news:W3********************@speakeasy.net...
Hello:
How can I validate the character encoding of the textbox in a form?
For instance, when the user fills out a form, I need to be sure that he is
typing in English (I mean uses Latin characters - not Russian, Hebrew etc.).
Do you know any JS code sample that I could use?
I would appreciate your help.
Thank you,
--
Peter Afonin
You could try something like below. For demonstration I have set it arbitrarily
to reject characters with a unicode > 196, although you would have to decide on
a range suitable for your needs.
For simplicity this algorithm checks only the last character typed. You may wish
to scan the entire text, either on a timed basis or when the field loses focus.
<html>
<body>
<FORM>
<input name="anglo" type=text size=40 onkeyup='latinCheck(this);'>
</FORM>
<SCRIPT>
function latinCheck(s)
{
if(s.value.length && s.value.charCodeAt(s.value.length-1) > 196)
{
s.value=s.value.substring(0,s.value.length-1);
alert('Illegal character typed');
}
}
</SCRIPT>
</body>
</html>
--
Stephen Chalmers