Q:

how to use Regex in password box in WPF

I wanted to test my input password in password box in WPF so that its only
aplhabets, digits and special characters.. I did the following code bt the loop is directly going to Else Loop. What should I do for its proper functioning?
Regex regex = new Regex("^(?=.+[A-Za-z])(?=.+\\d)(?=.+[$@$!%*#?&])[A-Za-z\\d$@$!%*#?&]{8,}$");
if (regex.IsMatch(txtPassword.ToString()))
{
    MessageBox.Show("Data Saved Correctly");   
}
else
{
    txtPassword.Clear();
    MessageBox.Show("Password should contain atleast one alphabet,number & special character");
}

A:

Use txtPassword.Password instead of txtPassword.ToString().
Good luck on your project :)

