简体   繁体   English

8位非重复数字的正则表达式

[英]Regex for 8 digits non repeating numbers

I want to make a regex for 8 digit non-repeating regex for phone number.我想为电话号码的 8 位非重复正则表达式制作正则表达式。 It should not match with 11111111 or 22222222.... 88888888它不应该与 11111111 或 22222222 匹配...... 88888888

I tried to make a Regex but it only matches for 1我试图制作一个正则表达式,但它只匹配 1

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

What corrections do I need in this?我需要对此进行哪些更正?

You can add this to your script js:您可以将其添加到您的脚本 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.捕获第一个数字,然后确保它不再重复 7 次。

Demo演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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