I need a RegEx to trigger a validation message when a user enters 2 repeating characters.
Asked
Active
Viewed 664 times
1 Answers
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