views:

26

answers:

2

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>&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Fill in a password." ControlToValidate="txtpassword"></asp:RequiredFieldValidator>
                    &nbsp;
<asp:CustomValidator ID="CustomValidator1" runat="server" OnServerValidate="valPassword" ErrorMessage="Password must be 6 characters long." ControlToValidate="txtpassword"></asp:CustomValidator>&nbsp;(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 ?

A: 

try changing txtpassword to an <asp:Textbox> instead of an input.

Andy_Vulhop
i've tried it but still the same problem
Janis
A: 

maybe a problem with name vs id? I usually try to have the name and the id of an element match to avoid confusion.

Mike
changed it but no , its not the trick
Janis