How to validate characters encoding in the textbox

P

Peter

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,
 
P

Peter

Thank you.

I think this applies only to the whole form, I need to apply this only to
the particular textboxes. I'll try though.

Peter
 
D

DU

Peter said:
Thank you.

I think this applies only to the whole form,

Yes it applies only to the whole form. The spec clearly mentions that
you can provide a comma-separated list of accepted charsets.

accept-charset %Charsets; #IMPLIED -- list of supported charsets --

"This attribute specifies the list of character encodings for input data
that is accepted by the server processing this form. The value is a
space- and/or comma-delimited list of charset values.(...)"
http://www.w3.org/TR/html401/interact/forms.html#adef-accept-charset

Browser support for this particular attribute with this unique feature
could be weak, partial, incomplete or buggy. I really don't know.

I need to apply this only to
the particular textboxes. I'll try though.

Peter


"A.3.13 Changes for internationalization

HTML 4.0 integrates the recommendations of [RFC2070] for the
internationalization of HTML.

However, this specification and [RFC2070] differ as follows:

* The accept-charset attribute has been specified for the FORM
element rather than the TEXTAREA and INPUT elements."
http://www.w3.org/TR/html401/appendix/changes.html#h-A.3.13

DU
 
P

Paul Gorodyansky

Peter said:
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,

I can be mistaken, but I guess you can *not* do such validation.
You may want to look here:
http://ppewww.ph.gla.ac.uk/~flavell/charset/form-i18n.html
 
S

Stephen Chalmers

What I said and what you wish I'd said,
may not be the same. Please quote the former.

Peter said:
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,

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top