Reputation: 47472
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.
Upvotes: 3
Views: 2941
Reputation: 138032
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.
Upvotes: 3
Reputation: 91385
what about:
var re = /^[a-zA-Z!#$%]+$/;
Fell free to add any special character you need inside the character class
Upvotes: 0
Reputation: 887365
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.
Upvotes: 0
Reputation: 152216
You can try with this regex:
^[^\d]*$
And sample:
var str = 'test123';
if ( str.match(/^[^\d]*$/) ) {
alert('matches');
}
Upvotes: 6