Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
how to validate password length on text changed event in asp.net??
Posted

 
Share this answer
 
Hi,
Try this:
C#
Regex pass = new Regex("^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$");
if(!pass.IsMatch(txtPassword.Text)){
    //Password should be min of 4 char. Error message
}
else{
   //Success.
}

The following regular expression is for a 4 to 8 char password and containing at least an alphabet and one Number. You can change numbers in the end to your allowed password length.



--Amit
 
Share this answer
 
C#
private void TextBox1_TextChanged(object sender, EventArgs e)
{
if(TextBox1.Length>=8)
  //then print password valid
else
  //not enough characters
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900