I'm trying to test if an input has at least 4 number and 1 character in it. I have this which works, but only when the characters are in the order 0000a
, I wanted it to match no matter what the order, so 00a00
, a0000
, aa00a00a
would all match the pattern.
[0-9]{4,}[a-zA-Z]{1,}
What do I need to change? I tried [a-zA-Z0-9]{5,}
but then things like aaaaa
and 00012
matched, which is no good.
Using lookahead assertion:
(?=.*[a-zA-Z])(.*?\d){4,}
Debuggex Demo
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