I have a form for registration. I'm checking if the password has 6 characters like this :
<input type="password" runat="server" name="password" size="41" maxlength="64" id="txtpassword" /><span>*</span>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Fill in a password." ControlToValidate="txtpassword"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server" OnServerValidate="valPassword" ErrorMessage="Password must be 6 characters long." ControlToValidate="txtpassword"></asp:CustomValidator> (at least 6 characters)
codebehind
protected void valPassword(object source, ServerValidateEventArgs args)
{
args.IsValid = ValidatePassword(args.Value);
}
private bool ValidatePassword(string pw)
{
if (pw.Length >= 6)
{
return true;
}
else
{
return false;
}
}
If I leave the RequiredFieldValidator and the CustomValidator work together and I fill in 1 character , the form is accepted.
If I delete the RequiredFiekdValidator and fill in the form, the form is accepted with no character at all in the passwordfield
If I leave the CustomValidator and I fill in 1 character , the form is accepted
My CustomValidator isn't working properly, what am I missing ?