detect string is japanese, not english

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
Suppose that on "A" form, I have 2 textboxes: "English" and "Japanese".
On "English" textbox will be inputted English string only, and "Japanese"
textbox will be inputted Japanese stirng only.
But in some case, my users input Japanese string into English textbox by
mistake.
Could anyone give me some code to insert into before update event to check
wether user in input to correct textbox?
Pls help me. I need your help.
Many thanks.
 
I'm not sure what a Japanese string looks like, so I can only comment on the
English side, but if you're talking about plain text input then I'd think
that you could loop through each character, check whether its >=a and <=z
(or the capitalised version, or both), and work out what percentage of the
characters fit that. If that percentage is less than 80 (for example, you'd
need to do some testing to see what a good threshold would be), then pop up
a warning.
 
Assuming that you're using a Unicode font, you can use AscW() to examine
the characters the user has entered and compare the values you get with
the Unicode ranges for the scripts you're interested in.

The ordinary roman alphabet is in the range 0041 to 007A (hex); hiragana
and katakana seem to be in 3040 to 30FF. See
http://www.unicode.org/charts/ for more.
 
Also: you may be able to avoid the problem by setting the
KeyboardLanguage property of the textboxes. If one is set to English and
the other Japanese, it will - I presume - be much harder for the users
to accidentally enter the wrong data.
 
I'm sorry to bother you. Could you write some code for me to loop through
each character, check whether its >=a and <=z?
many thanks
 
Something like this (where you're checking a field called 'whatever')

whatever_beforeupdate....
dim i as integer

'cntEnglish used to count how many 'English' chars

dim cntEnglish as integer

cntEnglish=0

'ToCheck used to strip out any chars you want to ignore

'e.g. spaces

dim ToCheck as string

ToCheck=replace(me.whatever, " ", "")

dim char as string

for i=1 to len(ToCheck)

'grab a char and make it lower case

char=lcase(mid(ToCheck, i, 1))

if (char>="a" and char<="z") then

cntEnglish=cntEnglish+1

end if

next

'0.7 or whatever value you find works

if cntEnglish/len(ToCheck)>0.7 then

'probably english

else

'suspect not english

end if

Having said that, I prefer John's idea of using KeyboardLanguage. Is that
not possible?
 
Thanks for your support.
I preffer yo usolution because in some case, user just copy japanese string
of other document (ex:word) and paste into that field. so set input locale
will not do the trick.
Thank you.
 
Back
Top