This must be simple and I expect it working in the same way but it's not helping me out.
using System;
using System.Text.RegularExpressions;
I am in a need of password validation regular expression
with certain conditions where -
1) It must contain at least a number
2) one upper case letter
3) 8 characters long.
public class Program
{
public static bool IsValidPassword(string plainText) {
Regex regex = new Regex(@"^(.{0,7}|[^0-9]*|[^A-Z])$");
Match match = regex.Match(plainText);
return match.Success;
}
public static void Main()
{
Console.WriteLine(IsValidPassword("shing")); //logs 'True' always
}
}
I've taken regex from this source- Password must be 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters
Issue is that it returns 'True' always and the string that I am sending to method is not valid.
Help me if I am doing something wrong with the regex.
Please play with it here- https://dotnetfiddle.net/lEFYGJ