Regular expressions are not particularly good at the fact that certain groups of characters appear a certain number of times. Although this is probably possible - it will no doubt be curtailed and not obvious.
If you are programming in .NET (C # or VB), you can use a simple check function, for example:
bool ValidatePasswordCompliance( string password ) { int countDigits = 0; int countAlpha = 0; int countOthers = 0; foreach( char c in password ) { countDigit += c.IsDigit ? 1 : 0; countAlpha += c.IsAlpha ? 1 : 0; countOther += !(c.IsAlpha || c.IsDigit) ? 1 : 0; } return countDigits >= 3 && (countDigits + countAlpha + countOthers) >= 7; }
If you are working with .NET 3.5 or higher, you can use LINQ to simplify this:
bool ValidatePasswordCompliance( string password ) { return password.Count() >= 7 && password.Count( x => x.IsDigit ) >= 3; }
source share