简体   繁体   中英

Regex for 8 digits non repeating numbers

I want to make a regex for 8 digit non-repeating regex for phone number. It should not match with 11111111 or 22222222.... 88888888

I tried to make a Regex but it only matches for 1

Example - ^(?..*([0-9])1{7})[0-9]{8}$

What corrections do I need in this?

You can add this to your script js:

function UpdateInput2(fun = '12345678') {    
arr = fun.split('');

for (let i = 0; i < arr.length; i++) {
    
    //for unique constant
    regex = /^(\d)(?!\1{7})\d{7}/g;
    str = fun;
    index = str.search(regex);
    fun = replaceIndex(fun, index, str[index] + '*');

}

$("#output").val(fun);

}

Do this:

^(\d)(?!\1{7})\d{7}$

Capture the first digit and then ensure that it is not repeated 7 more times.

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM