Hi all,
I've got a regular expression which checks for the existence of a uppercase, lowercase and number within a string. I've tested it with two regular expression tools and it works perfectly.
However when I call RegEx.IsMatch, it always returns true. Here's my code:
Code:
private static string _upperLowerNumericPattern = @"^(?!.*(.)\1{100,})((?=.*[\d]+)(?=.*[A-Z]+)(?=.*[a-z]+)).{0,}$";
public static string GenerateAlphaNumericValue(int length, bool mustContainUpperLowerCaseAndNumber)
{
if (length < 3 && mustContainUpperLowerCaseAndNumber)
throw new ArgumentException("Minimum length of string must be 3 characters if string must contain uppercase, lowercase and number.");
string generatedValue = string.Empty;
bool patternMatched = false;
while(!patternMatched)
{
//Call method to generate string - test by setting generatedValue to your own test value
generatedValue = GenerateAlphaNumericValue(length);
if(Regex.IsMatch(generatedValue,_upperLowerNumericPattern));
patternMatched = true;
}
return generatedValue;
}