Checking for consecutive char's
Posted: Thu Jul 13, 2006 7:41 am
A friend has asked me if I know of a pattern to detect repeated characters in a string, he is using it for 'password authentication' where he has the rules : 8-12 chars, alphanum only, first char must be alpha', and password must not contain consecutive char's more than twice.
Namely he wants to stop people using 'aaaaaaa' as their password etc.
So, the others we have sorted, but the consecutive char's is posing problems. Can regex detect consecutive characters, and importantly, can we specify the limit?
After some thought 'No' is the answer, but posting for a 'second opinion' given I am not a RegEx god :p
and for the sake of it, this is what we have come up with for the other rules (but have not tested):
Namely he wants to stop people using 'aaaaaaa' as their password etc.
So, the others we have sorted, but the consecutive char's is posing problems. Can regex detect consecutive characters, and importantly, can we specify the limit?
After some thought 'No' is the answer, but posting for a 'second opinion' given I am not a RegEx god :p
and for the sake of it, this is what we have come up with for the other rules (but have not tested):
Code: Select all
^([a-zA-Z]+?[a-zA-Z0-9]+){8,12}$