我需要一个正则表达式来在用户输入 2 个重复字符时触发验证消息。
最佳答案
嗯
var repeats = /(.)\1/;
将匹配任何其中重复字符的字符串。
因此
if (repeats.test("hello")) alert("true because of the two 'l' characters");
和
if (!repeats.test("frederick the great")) alert("test fails because no characters repeat");
关于javascript - 有人可以给我一个示例 JavaScript RegEx 来使输入的 2 个重复字符无效吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4820944/