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
You 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.
1 Comment
Jonathon
The second regex should be slightly more efficient and is as far as I can tell the best answer.