日文字符的正则表达式

我正在使用 Struts 进行国际化.我想为日语和英语用户编写 Javascript 验证.我知道英语的正则表达式,但不知道日语用户.是否可以为基于Unicode验证的两个用户编写一个正则表达式?

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?

请帮帮我.

推荐答案

这是一个正则表达式,可用于匹配所有英文字母数字字符、日文片假名、平假名、多字节字母数字(hankaku 和 zenkaku)和破折号:

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

您可以根据需要对其进行编辑,但请注意末尾的u"标志.

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

我希望这会有所帮助!

相关文章