tags:

views:

97

answers:

1

I want to prevent this kind of typing:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbnonsense

for that I want to check that a certain letter gets repeated more than 9 times:

preg_match('/.{9,}/',$key)

but this would suit any word that has more than 9 letters in it, such as: supercalifregilisticexpealidocious

How do I do this?

+12  A: 

You need a back reference to match the same character multiple times:

preg_match('/(.)\1{8}/', $string);
soulmerge
And you'll probably want something like `[^-=*\s]` instead of `.`, since whitespace (especially for blank lines) and the other characters are often intentionally repeated. The exact character set will depend on your audience and what they're entering.
Roger Pate