How to match all language characters like English, Greek, Chinese, except for special characters

I have a display name field that I have to check with JavaScript regex. We must match all language characters, such as Chinese, German, Spanish, in addition to English characters, except for special characters such as * (). I am amazed at how to match these non-Latin characters. Any help was appreciated.

+4
source share
3 answers

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

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

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

+2
source

Unfortunately, unicode support for unicode regular expressions is not supported in javascript.

0
source

I used the XRegExp bit for this kind of thing, and it worked as expected. Unicode plugins are available here: http://xregexp.com/plugins/

0
source

Source: https://habr.com/ru/post/1308336/


All Articles