不允许数字 (0-9) - javascript 中的正则表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4440286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
numbers not allowed (0-9) - Regex Expression in javascript
提问by Sanju
I want a regex pattern which will allow me any chars, but it will not allow (0-9) numbers?
我想要一个正则表达式模式,它允许我使用任何字符,但不允许 (0-9) 数字?
回答by jjnguy
Simply:
简单地:
/^([^0-9]*)$/
That pattern matches any number of characters that is not 0through 9.
该模式匹配任意数量的不0通过的字符9。
I recommend checking out http://regexpal.com/. It will let you easily test out a regex.
我建议查看http://regexpal.com/。它将让您轻松测试正则表达式。
回答by SLaks
Like this: ^[^0-9]+$
像这样: ^[^0-9]+$
Explanation:
解释:
^matches the beginning of the string[^...]matches anything that isn'tinside0-9means any character between 0 and 9+matches one or more of the previous thing$matches the end of the string
^匹配字符串的开头[^...]匹配任何不在里面的东西0-9表示 0 到 9 之间的任何字符+匹配一个或多个先前的事物$匹配字符串的结尾
回答by Pranav Singh
\Dis a non-digit, and so then \D*is any number of non-digits in a row. So your whole string should match ^\D*$.
\D是非数字,因此\D*是任意数量的非数字。所以你的整个字符串应该匹配^\D*$.
Check on http://rubular.com/r/AoWBmrbUkNit works perfectly.
检查http://rubular.com/r/AoWBmrbUkN它完美运行。
You can also try on http://regexpal.com/OR http://www.regextester.com/
回答by josh.trow
Something as simple as [a-z]+, or perhaps [\S]+, or even [a-zA-Z]+?
像这样简单的事情[a-z]+,或者也许[\S]+,甚至[a-zA-Z]+?

