[英]Can someone give me an example JavaScript RegEx to invalidate 2 repeating characters from being entered
當用戶輸入2個重復字符時,我需要一個RegEx來觸發驗證消息。
好
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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.