As far as I know, it is not feasible to detect sequence of numbers with regex
.
It is possible to detect repeated characters easily, such as 000 or aaa, but a sequence 123, 987 or abc not.
The regex
by itself, does not assign value to characters. It nay identifies that 2
is greater than 1
or that b
is followed by a
in the alphabet.
To do this you would have to write all possible sequences for it to give match in any of them. As an example to Pattern "123|12|23|321|32|21
" to identify a single sequence between three numbers.
For repeated letters or numbers you could use a Pattern searching for repeated occurrences such as "(\d|\w)\1+
".
In that case the Pattern gets a letter or number and then checks if it repeats once or more.
See working on regex101.
If I were your user, I would appreciate it if you didn’t restrict the password (even more so at this level). Good luck.
– Renan Gomes
How many repeated characters will be considered to say that the password has to be in this validation, for example the password aa123r56, would be valid? your password will always be composed by 8 characters?
– Marco Souza
the password aa123r56 would not be valid because there is a repeat sequence in aa and 123 in the same password at first yes would be 8 characters possibly will increase the value of the field. I used a previous solution but, it did not suit me well, because of the documentation.
– willmskw
It seems that detecting sequences using regex is not possible. See this topic in Soen, it may help. http://stackoverflow.com/questions/8880088/regular-expression-to-match-3-or-more-consecutive-sequential-characters-and-cons
– Celso Marigo Jr
As far as I know, it is not possible to detect sequence of numbers with regex. It is possible to detect repeated numbers or letters, such as
000
oraaa
, but a sequence123
,987
orabc
nay.– Daniel Dutra
You mean if my birth year was 1987 I couldn’t use it because it was sequential?
– Guilherme Lautert