简体   繁体   English

正则表达式只匹配字母,空格和非英语字符?

[英]Regular expression to match only letters, space and non-English characters?

I am trying to check text with regular expression and i need to check if it contains only letters, spaces and also non english characters. 我正在尝试使用正则表达式检查文本,并且需要检查它是否仅包含字母,空格以及非英语字符。

I have this one: 我有这个:

var check = /^[a-zA-Z_0-9][a-zA-Z_0-9\s]*$/g.test(input.value);

It works fine but if input.value contains "ã" or "é" it gives false. 它可以正常工作,但如果input.value包含“ã”或“é”,则为false。

I googled and find that you can use unicode filter like this: 我用Google搜索,发现可以使用Unicode过滤器,如下所示:

/\p{L}/u

I tryed to combine but with no results. 我试图合并,但没有结果。

How can i solve this? 我该如何解决?

Thank you all. 谢谢你们。

The following will include extended latin characters: 以下内容将包含扩展的拉丁字符:

var check = /^[a-zA-Z_0-9\u00C0-\u017F][a-zA-Z_0-9\u00C0-\u017F\s]*$/g.test(input.value);

See https://en.wikipedia.org/wiki/Latin_script_in_Unicode for more information. 有关更多信息,请参见https://en.wikipedia.org/wiki/Latin_script_in_Unicode

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

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