Checking For A String Which Contains 3 Consecutive Letters And 2 Digits In Any Order
Solution 1:
The regex you are describing can be written like so:
/(?=.*?[a-z]{3})(?=.*?\d.*?\d)/
The first lookahead searches for three letters in a row, in any position. The second lookahead looks for a digit in any position, followed by a digit further ahead.
Solution 2:
You should probably do this in two separate regular expressions: one to test for three consecutive letters and one to test for at least two digits:
/[a-z]{3}/i
/\d.*d/
Make sure both conditions are met. You could use lookahead to combine this into one regex, but I think two regexes is clearer code and a better solution.
But if I may inject some opinion on the matter: Unless you have no control over this (client specified this), I'd highly recommend not imposing password restrictions like this. They actually make your password system far less secure, not more secure. Some reading on why:
http://jimpravetz.com/blog/2011/06/cheap-gpus-are-rendering-strong-passwords-use/
Post a Comment for "Checking For A String Which Contains 3 Consecutive Letters And 2 Digits In Any Order"