Home > database >  Regex for 8 digits non repeating numbers
Regex for 8 digits non repeating numbers

Time:12-22

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?

CodePudding user response:

Do this:

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

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

Demo

  • Related