0

I need a RegEx to trigger a validation message when a user enters 2 repeating characters.

Amen
  • 693
  • 4
  • 15
  • 28

1 Answers1

4

Well

var repeats = /(.)\1/;

will match any string with a character repeated in it.

Thus

if (repeats.test("hello")) alert("true because of the two 'l' characters");

and

if (!repeats.test("frederick the great")) alert("test fails because no characters repeat");
Pointy
  • 389,373
  • 58
  • 564
  • 602