简体   繁体   English

如何匹配所有语言字符(如英语,希腊语,中文)(特殊字符除外)

[英]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. 我有一个显示名称字段,必须使用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. 如果您的正则表达式引擎可以匹配Unicode类别,则正则表达式\\p{L}匹配任何语言的任何字母。 JavaScript does not support Unicode categories. JavaScript不支持Unicode类别。 If you use XRegExp with the Unicode plugin , then you can do it like this in JavaScript: 如果将XRegExp与Unicode插件一起使用 ,则可以在JavaScript中这样做:

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

This will return true if $input consists of one or more letters and nothing else. 如果$ input由一个或多个字母组成,并且没有其他内容,则返回true。

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

I've used bits of XRegExp for this kind of thing and it's worked as expected so far. 我已经使用XRegExp进行这种事情,到目前为止,它已经按预期工作了。 There's Unicode plug-ins here: http://xregexp.com/plugins/ 这里有Unicode插件: http : //xregexp.com/plugins/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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