Regular Expression for Japanese characters

前端 未结 3 1592
-上瘾入骨i
-上瘾入骨i 2020-12-05 15:43

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 u

3条回答
  •  醉酒成梦
    2020-12-05 16:28

    As long as you save your scripts in the same character set as your page (e.g. both HTML and JavaScript are UTF-8 or both HTML and JavaScript are Shift_JIS), you should be able to treat your regular expressions exactly the same as you would with English.

    function isKansai(city) {
        var rxKansai = /(大阪|兵庫|京都|滋賀|奈良|和歌山|osaka|hyo{1,2}go|kyoto|shiga|nara|wakayama)/i;
        return rxKansai.test(city);
    }
    isKansai('東京'); // false
    isKansai('大阪'); // true
    isKansai('Tokyo'); // false
    isKansai('Osaka') // true
    

提交回复
热议问题