Reputation: 340
I have an regular expression:
^(?!(?:(\d)\1+[ -]*)+$)\d[\d- ]+$
Demo: http://regex101.com/r/sB1tK3/1
As you can see it not allowing strings which have all characters identical, but it checks only numbers.
How would I make that same regex checks letters (dashes and spaces shoud be still allowed) e.g:
aaaaa - it's not ok
aa-aaa-aaa-aaaaa - it's not OK
ababab - it's OK
ab-ab-ab - it's OK
Regards
Upvotes: 1
Views: 33
Reputation: 784998
You can use \w
in place of \d
to match [a-zA-Z0-9_]
:
^(?!(?:(\w)\1+[ -]*)+$)\w[\w -]+$
Upvotes: 2