I tried a few days with this check. I am working with Javascript to check a user's PIN for 4 digits, which should not accept adjacent duplicate digits such as 1135or 1552etc. It should not take a sequence of numbers, for example: 1234or 3456or even 1275(0 sequence numbers, such as 12** *56*, **87, 21**(i.e. neither ascending or descending sequence).
I tried modifying the regex from this answer from @polygenelubricants
Its regular expression is as follows:
^(?=\d{4}$)(?:(.)\1*|0?1?2?3?4?5?6?7?8?9?|9?8?7?6?5?4?3?2?1?0?)$
But it also matches 3579, which in my case should be resolved, so I changed it to something like this (which in my head means matches all 4-digit numbers, then find all the numbers and check, they don't repeat more than once OR if he does not find next to him 0and 1or 1and 2next to him ... (and the same for a decreasing order))
^(?:\d{4}$)(?:(.)(?!\1)|0?1?|1?2?|2?3?|3?4?|4?5?|5?6?|6?7?|7?8?|8?9?|9?8?|8?7?|7?6?|6?5?|5?4?|4?3?|3?2?|2?1?|1?0?)$
However, when I tested it, I get all 4 digits of the digits, but I don’t evaluate whether they are repeated several times or ordered.
See startup example
source
share