简体   繁体   中英

Change RegEx to allow for both English & Japanese characters

This is my regular expression code:

"onlyLetterSp": {
    "regex": /^[a-zA-Z\ \']+$/,
    "alertText": "* Letters only"
}

How can I change this to allow English characters as well as Japanese?

I found this link:

http://www.localizingjapan.com/blog/2012/01/20/regular-expressions-for-japanese-text/

There are apparently a few different character sets for different types of Japanese.

Hiragana for example is:

[\x3041-\x3096]

You must be looking for the u regex modifier, which stands for Unicode . With it you can use POSIX symbols like \\w to include whatever "word" characters you like

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM