469,319 Members | 2,429 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

input (text) onkeypress with Japanese characters

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

Sep 8 '05 #1
3 4267
Is there any other information I can provide that would help to receive
a response on this topic? It's quite confusing. ;)

James

Sep 9 '05 #2
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

Sep 9 '05 #3
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

Sep 9 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Thomas | last post: by
1 post views Thread by Robert Nurse | last post: by
11 posts views Thread by jimstruckster | last post: by
44 posts views Thread by Kulgan | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.