开发者

Can someone give me an example JavaScript RegEx to invalidate 2 repeating characters from being entered

开发者 https://www.devze.com 2023-02-07 06:57 出处:网络
I need a RegEx to trigger a validation message when a user enters 2 r开发者_如何学Goepeating characters.Well

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消