0

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

Amen
  • 713
  • 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
  • 405,095
  • 59
  • 585
  • 614