I need help with a problem I have, I need you to validate that there are no consecutive values; what I mean is that you cannot put:
123 or abc or 345 or cdf. etc
I currently have this regular expression:
^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[$#@&*_+-])(?!.*(.)\1{2})[a-zA-Z0-9$#@&*_+-]{8,15}$
Which validates the following: if it has uppercase, one lowercase, if it has a number, if it has special characters and that an identical character is not repeated more than 3 times, with a minimum length of 8 and a maximum of 15
Example:
HsEsp3$6_* --Valid
HsEsp3$666_* --invalid
The only thing I need is to validate that there are no consecutive values, can it be done with a regular expression or does it have to be done in another way???
I don't think that with regular expressions it is possible to find out if it has consecutive characters, but with a bit of code and a loop
for
if possible, here is my solution:I hope it helps you, Greetings!
Another option without using regular expressions. The operation is simple: it compares the value of the current character vs. the previous one and checks if they have a difference of 1. If so, it is because they are consecutive.
The function also has a variable number of characters that you want not to be repeated
consec
, and I put another argumentreverse
if you want to disable the evaluation in reverse (654...).If you notice the last case "fails", this is because
?
@
andA
are consecutive characters . You would have to modify the code so that if the current character is not a letter or number it doesn't do the comparisons, but if you don't care, leave it at that.I don't think an integer regular expression is a good idea, because it would be very messy.
Why don't you instead check each of those rules in the chain consecutively?
I don't know how it would be in javascript, but something like:
In
(.)\1{2,}
, if the condition is met, then you throw an exception with password validation.In this way, each condition can be placed within a series of validators that return each case that is NOT met in the password. For example:
You could use the following regular expression, which checks if there are continuous repeating characters in the text you enter.
Let's look at an example: