regex to find numbers with unique digits

前端 未结 5 774
忘了有多久
忘了有多久 2020-12-10 13:19

I want to find 10 digit numbers with no repeat digits, for example:

1123456789 //fail, there are two 1\'s
6758951230 //fail, there are two 5\'s
6789012345 //         


        
5条回答
  •  半阙折子戏
    2020-12-10 14:15

    Try this one (?:([0-9])(?!.*\1)){10}, this will work if you're validating numbers one at a time.

    This should work (?:([0-9])(?!\d*\1)){10} to search for each occurance of an unique 10-digit sequence, but it will fail with 12345678901234567890, will find the last valid part 1234567890 instead of ignoring it.

    Source and explanations: https://stackoverflow.com/a/12870549/1366360

提交回复
热议问题