简体   繁体   中英

how to match all language characters like english, greek, chinese except the special characters

I have a display name field which i have to validate using JavaScript regex. We have to match all language characters like chinese, german, spanish in addition to english language characters except special characters like *(). I am struck on how to match those non-latin characters. Any help appreciated.

If your regular expression engine can match Unicode categories, the regex \\p{L} matches any letter in any language. JavaScript does not support Unicode categories. If you use XRegExp with the Unicode plugin , then you can do it like this in JavaScript:

XRegExp('^\\p{L}+$').test($input)

This will return true if $input consists of one or more letters and nothing else.

不幸的是,JavaScript中对Unicode正则表达式的Unicode没有太多支持

I've used bits of XRegExp for this kind of thing and it's worked as expected so far. There's Unicode plug-ins here: http://xregexp.com/plugins/

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