开发者

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

开发者 https://www.devze.com 2022-12-28 09:05 出处:网络
I have a display name field which i have to validate using JavaScript regex. We have to matchall language characters like chinese, german, spanish in addition to english language characters except spe

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 lik开发者_开发问答e *(). 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.


Unluckily there isnt much support for unicode for unicode regular expressions in javascript


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号