On Mon, Feb 17, 2003 at 07:40:46PM -0000, Matt Groves wrote: > > Hello, > > I'm looking for the shortest, cleverest possible solution to this. When > changing a password, I need a RegExp which will ensure the following > criteria : > > 1. It must be at least 6 characters > > 2. It must contain at least one lower case letter [a-z] > > 3. It must contain at least one upper case letter [A-Z] > > 4. It must contain at least one number [0-9] > > 5. Optionally, it can cover for accepted non-alphanumeric chars such as > "_", "-" etc (but not "#"), and a maximum password length of 14 > characters
I'm not going to claim this is the shortest solution, but this is very straightforward (and untested): /^(?=.{6}) # At least 6 characters long. (?=.*[a-z]) # Contains a lowercase letter. (?=.*[A-Z]) # Contains an uppercase letter. (?=.*[0-9]) # Contains a digit. (?=.*[-_]) # Contains a dash or an underscore. (?!.{15}) # Doesn't contain 15 characters. /xs; It's easy to add more requirements. Abigail