Q:

match if string list has specific string c# tried .Any

i have to add validator for password column, i.e. it should not allow "Password" word in Password at any stage.. means "Password@1234" should not be allowed. So i was using below code which is working fine:
Regex.IsMatch(viewModel.Password.ToUpper(), @"(\w*PASSWORD\w*)", RegexOptions.IgnoreCase)

Now i want to compare multiple words means it should not contains "Password" or "Hello" lets say. I have tried ".Any" but it is not working.
if (myList.Any(str => str.Contains("Password")))

I have followed:
Check if a string within a list contains a specific string with Linq
for Any 
Please help. 

A:

Yes, you can try Linq Any (word definition is a complex question, that's why let me stick to your pattern: \w*{word_to_find}\w*):
  List<string> ForbiddenWords = new List<string>() {
    "this",
    "password",
    "bla-bla-bla",
    "123",
  };

  Regex[] invalidPasswords = ForbiddenWords
    .Select(word => new Regex($@"\w*{Regex.Escape(word)}\w*", RegexOptions.IgnoreCase))
    .ToArray();

  ...

  if (invalidPasswords.Any(regex => regex.IsMatch(viewModel.Password))) {
    // Password is invalid it contains forbidden word(s)
  } 

Let's have some demonstration:
  string[] tests = new string[] {
    "MyPassWord",
    "PassWord",
    "PassWord@123",
    "PassWord@5678",
    "It's_PassWord@5678",
    "ABC123",
    "123",
    "1234",
    "pass",
    "word",
    "swar",
  };

  Func<string, bool> Validator = (password) => 
    !invalidPaswords.Any(regex => regex.IsMatch(password));

  string report = string.Join(Environment.NewLine, tests
    .Select(test => $"{test,-20} : {(Validator(test) ? "OK" : "Invalid")}"));

  Console.Write(report);

Outcome:
MyPassWord           : Invalid
PassWord             : Invalid
PassWord@123         : Invalid
PassWord@5678        : Invalid
It's_PassWord@5678   : Invalid
ABC123               : Invalid
123                  : Invalid
1234                 : Invalid
pass                 : OK
word                 : OK
swar                 : OK

