I am trying to make sure that user uses at least 6 characters as a password in my program.
I know how to set maximum size by using MaxLength, but how I do this for the minimum length?
EDIT: How do I check if a string has less or more than 6 characters?
Small bug - when I start typing password I am being presented that password is too short until person entered 6 characters. When 6 or more characters is entered I am showing that password is valid. But, when I type 6 characters, and then remove, the check only react when there is 4 characters. But shouldn't it be tricked when there is less than 6 characters?
protected void KeyDownCheck(object sender, KeyEventArgs e) { bool validPass = txtPassword.Text.Length < 6; if (validPass) lblMessage.Text = "Password can not be shorter than 6 characters!"; else lblMessage.Text = "Password is valid."; }