Reputation: 161
I'd like to check a "textarea" field to make sure it doesn't contain characters repeated 3 or more times like listed below:
aaaaaaaaaaaaaaaaaa
ggggggggggggggg
ddddddddddddd
How can I do this using Javascript or Jquery?
Upvotes: 0
Views: 48
Reputation: 11773
I agree with Pinch, but if you want to do it manually, you could always:
0
to length-2
, and check to see if the following 2 are not the same as the current.Did I say I agree with pinch already? :)
Upvotes: 0
Reputation: 4207
You can accomplish this using regular expressions:
var hasDuplicate = (/^([a-zA-Z])\1+$/).test(str)
Upvotes: 2