Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question password compare

    Hi
    I want the user to enter their password twice to avoid errors. Below is an extract of my current code.
    I have now put two inputs for their email address. How do I change my code to check if both are the same please.
    <input TYPE="text" NAME="email">
    <input TYPE="text" NAME="email2">


    if (!validateInputBox(document.theForm.nickname.value))
    { isValid = false; alert(' Please fill in your name.'); }
    if (!validateInputBox(document.theForm.vpassword.value))
    { isValid = false; alert(' Please fill in the password of your message.'); }
    if (!validateEmail(document.theForm.email.value))
    { isValid = false; alert(' Please fill in a correct email address.'); }



    if (isValid)
    alert ("Thank you. Your form is being sent.");
    return isValid;
    }
    function validateInputBox(text) {
    return (text.length > 0);
    }
    function validateEmail(emailAddress) {
    var match = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/.test(emailAddress);
    return match;
    }
    cheers Peter

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    if ((document.theForm.email.value) != (document.theForm.email2.value))
    { isValid = false; alert('email addresses not the same - please re-enter');
    document.theForm.email2.value = "";
    document.theForm.email.value = "";
    document.theForm.email.value.focus();
    }

    If the two match then you can proceed to test whether the address is syntactically valid.
    Last edited by Philip M; 07-06-2006 at 07:53 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •