I'm looking for a regex that will validate my string. The string should
How can this be done?
You can use negative lookahead assertion as:
^(?!.*[0-9].*[0-9].*[0-9].*[0-9]).{6,25}$
See it
which ensures that there are no 4 digits in your input.
This can be achieved with a lookahead assertion:
^(?=(?:\D*\d){0,3}\D*$).{6,25}$
Explanation:
^ # Start of string
(?= # Assert that the following can be matched here:
(?:\D*\d) # Any number of non-digits, followed by one digit
{0,3} # (zero to three times)
\D* # followed by only non-digits
$ # until the end of the string
) # (End of lookahead)
.{6,25} # Match 6 to 25 characters (any characters except newlines)
$ # End of string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With