Regular Expression for Japanese characters

Nilesh Shukla picture Nilesh Shukla · Jul 22, 2011 · Viewed 22.5k times · Source

I am doing internationalization in Struts. I want to write Javascript validation for Japanese and English users. I know regular expression for English but not for Japanese users. Is it possible to write one regular expression for both the users which validate on the basis of Unicode?

Please help me.

Answer

shawndreck picture shawndreck · May 9, 2012

Here is a regular expression that can be used to match all English alphanumeric characters, Japanese katakana, hiragana, multibytes of alphanumerics (hankaku and zenkaku), and dashes:

/[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+|[a-zA-Z0-9]+|[a-zA-Z0-9]+|[々〆〤]+/u

You can edit it to fit your needs, but notice the "u" flag at the end.

I hope this helps!