Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string have uppercase, lowercase and number

I want to check if my string have Uppercase & LowerCase & Number

string myString = "Hello123";

if (myString haveUppercase && myString haveLowerCase && myString haveNumber)
{
    this.hide();
}
else
{
    MessageBox.Show("Error!");
}
like image 988
alix54 Avatar asked Sep 02 '25 15:09

alix54


2 Answers

You can use char's methods with LINQ:

if (myString.Any(char.IsUpper) &&
    myString.Any(char.IsLower) &&
    myString.Any(char.IsDigit))
like image 110
Selman Genç Avatar answered Sep 05 '25 05:09

Selman Genç


if (myString.Any(ch => char.IsUpper(ch) &&
    myString.Any(ch => char.IsLower(ch) &&
    myString.Any(ch => char.IsDigit(ch))
    { 
      this.hide();
    }
    else
    {
        MessageBox.Show("Error!");
    }
like image 20
Amir Popovich Avatar answered Sep 05 '25 03:09

Amir Popovich