input (text) onkeypress with Japanese characters

A

addi

I'm looking to perform input validation on an HTML input text element;
specifically, I'm looking to prevent anything other than numerical
characters from being entered.

I've got it working just fine for English characters by using an
'onkeypress' event handler, where basically all that is done is a
regular expression check of the character represented by
window.event.keyCode against a string containing "0123456789".

The problem I'm running into is when I switch from English to Katakana
characters - I can type in any character just fine, which is of course
wrong! The 'onkeypress' event doesn't get triggered whatsoever. I was
told by a coworker to handle the 'onpaste' event, but while that covers
yet another case for invalid input, the issue still persists: Katakana
characters of any kind can be typed into the text input without
triggering the 'onkeypress' or 'onpaste' events.

I'm using IE 5.5+ on Windows XP SP2 Japanese.

I hope someone has some experience with this. Thanks in advance for
any constructive feedback.

James
 
A

addi

Is there any other information I can provide that would help to receive
a response on this topic? It's quite confusing. ;)

James
 
D

Donius

Well, heck, james, i don't know much of anything about japanese
encoding, or more than being able to repeat the katakana that i learned
in my half year of japanese class, but i can try to give you some sort
of answer!

If you're validating with javascript, instead of limiting what the user
can & can't type in a particular box ((and i know it's slicker that
way, but)), perhaps you should wait until form submission time and
validate then, using the formelement.onsubmit event. Go through then
with your regex to see what kind of data is in there, and if the
javascript regex can correctly deal with katakana, that should be it!

Your coworker was right in that the onkeypress won't usually be
activated because when you type, the onkeypress works, but behind the
scenes, whatever the operating system is is gimmicking in the katakana:
you're entering it, it's figuring out what katakana you mean, and then
it's pasting it wherever is focused.

So, I'm not sure that you can get an "as you type" input for the
"strange" characters that are katakana and cryllic and whatnot, so
maybe the solution is not to try for that, but try for something you
can be sure of, like a form submission.

Hope that helps in some way,
-Brendan
 
A

addi

Brendan,

First of all, thanks a lot for your response. It's good to see that
someone else sees it as I do... however, I don't have the option to
validate on submission of a form. The requirements dictate that it
pretty much has to be as close to 'onkeypress' as possible.

Now, you mention that in behind the scenes, the katakana characters are
being manipulated and then pasted in - there must be some way to catch
that. You'd think that 'onpaste' would be the ideal event, but as I've
already mentioned, that appears to be a bust.

I can't believe that there isn't a way to accomplish what I need to do
for all languages. Seems silly.

Thanks again, and if anyone has any further insight, please feel free
to share.

James
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top