Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex (or other) to detect presence of 1-byte Kanji or Katakana chars 1

Status
Not open for further replies.
Dec 8, 2003
17,047
GB
I'm creating a sign-up form for the Japanese version of a site, and there are two 'name' fields, one for Kanji, and one for Katakana. Both are mandatory. The only restriction is that both must only contain 2-byte characters.

My knowledge of Japanese is next-to-nothing, and after staring at pages on Wikipedia all day, my head hurts :), although I've managed to find out that there are single-byte Japanese characters (previously, I'd assumed all Japanese characters would be 2-byte).

Does anyone know if it's possible to detect the presence of 1-byte Japanese characters in a standard text-input field using a regular expression (to make it easier to plug into our validation routine), and if not, any method that I might use?

Many thanks in advance,

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hmm... I think I have it with this:

Code:
/^[^\uFF60-\uFF9F]+$/

although if anyone who knows more about Japanese character entry that me can confirm this, I'd really appreciate it.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
There are two kinds:
[1] half-width katakana; and
[2] katakana phonetic expression

The regex to detect them is:
[tt]
var rx=/[\uff66-\uff9d]|[\u31f0-\u31ff]/;
//s the string read to the memory to be tested.
if (rx.test(s)) {
alert("contains invalidate katakana characters);
} else {
alert("pass the filtering of half-width katakana or katakana phonetic expression");
//do further testing
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top