admin管理员组文章数量:1317909
I need a regex
which check the string contains only A-Z
, a-z
and special characters
but not digits
i.e. (0-9
).
Any help is appreciated.
I need a regex
which check the string contains only A-Z
, a-z
and special characters
but not digits
i.e. (0-9
).
Any help is appreciated.
4 Answers
Reset to default 6You can try with this regex:
^[^\d]*$
And sample:
var str = 'test123';
if ( str.match(/^[^\d]*$/) ) {
alert('matches');
}
Simple:
/^\D*$/
It means, any number of not-a-digit characters. See it in action…
The alternative is to reverse your test. Just check if there's a digit present, using the trivial:
/\d/
…and if that matches, your string fails.
You're looking for a character class: ^[A-Za-z.,!@#$%^&*()=+_-]+$
.
The ^
and $
anchor the regex by marching the beginning and end of the string, respectively.
what about:
var re = /^[a-zA-Z!#$%]+$/;
Fell free to add any special character you need inside the character class
本文标签: regexhow to check digits present in javascript string or notStack Overflow
版权声明:本文标题:regex - how to check digits present in javascript string or not - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742026905a2415713.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论