I need a RegEx to trigger a validation message when a user enters 2 r开发者_如何学Goepeating characters.
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");
精彩评论