Announcement

Collapse
No announcement yet.

validate password length javascript

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • validate password length javascript

    hi guys, ive currently done a code which validates wether or not 2 password boxes match with success but would like to validate the password length too, everytime i try to do this, one script just overwrites the other.

    this is my current script.

    Code:
    <script language="javascript"> 
    document.forms[0].onsubmit = function() 
    { 
    if 
    (this.elements['password'].value != this.elements['passwordconfirm'].value) 
    { 
    alert('Passwords do not match'); 
    return false; 
    } 
    
    return true; 
    } 
    </script>
    where abouts would i put the password validation length in that script above and what would the code be?

    could osmebody please give me a sample in my script above?

    regards
    Last edited by Rems; 2nd October 2008, 18:49.

  • #2
    Re: validate password length javascript

    Like this ...?

    The JavaScript Source: Forms: Validation (password)

    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: validate password length javascript

      Originally posted by Rems View Post
      Like this ...?

      The JavaScript Source: Forms: Validation (password)

      \Rems
      yes tried that one already, doesnt work
      Last edited by andysutils; 1st October 2008, 21:54.

      Comment


      • #4
        Re: validate password length javascript

        ok ill post what ive done so far

        these 2 scripts work 100% but only on there own


        script one

        Code:
        <script language="JavaScript" type="text/javascript">
        <!--
        function ValidatemyForm(theForm)
        {
        if (theForm.Editbox1.value.length < 5)
        
        {
           alert("Please enter at least 5 characters in the \"Editbox1\" field.");
           theForm.Editbox1.focus();
           return false;
        }
        return true;
        }
        </script>

        script two
        validate password match
        Code:
        <script language="javascript"> 
        document.forms[0].onsubmit = function() 
        { 
        if 
        (this.elements['password'].value != this.elements['password_confirm'].value) 
        { 
        alert('Passwords do not match'); 
        return false; 
        } 
        
        return true; 
        } 
        </script>

        everytime i put them both in together, which ever script is above the other stops the one below from working
        Last edited by Rems; 2nd October 2008, 18:48.

        Comment


        • #5
          Re: validate password length javascript

          (I edited your posts, I have wrapped the code between [code] -tags.)

          The script in the link works just fine when I test it (? - can you describe the problems you experience with that script?)
          Can you give the code you have including the form, so I am able to test yours and try merging the two separate scripts if I can.

          \Rems
          Last edited by Rems; 2nd October 2008, 18:53.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: validate password length javascript

            thanks rems, here is the full code from my .php file, do you have an addy i can pm the file itself too?

            Moderator Edit: "added [code]-tags around the code" .\Rems
            Code:
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
            <html>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
            <title>Untitled Page</title>
            <script language="JavaScript" type="text/javascript">
            <!--
            function ValidatemyForm(theForm)
            {
            if (theForm.Editbox1.value.length < 5)
            {
               alert("Please enter at least 5 characters in the \"Editbox1\" field.");
               theForm.Editbox1.focus();
               return false;
            }
            return true;
            }
            //-->
            </script>
            </head>
            <body bgcolor="#FFFFFF" text="#000000">
            <div id="wb_Form1" style="position:absolute;left:42px;top:96px;width:398px;height:263px;z-index:3" align="left">
            <form name="myForm" method="post" action="feedback.php" id="Form1" onsubmit="return ValidatemyForm(this)">
            <input type="submit" id="Button1" name="Button1" value="Submit" style="position:absolute;left:154px;top:216px;width:96px;height:25px;font-family:Arial;font-size:13px;z-index:0">
            <input type="password" id="Editbox1" style="position:absolute;left:100px;top:19px;width:250px;font-family:Courier New;font-size:16px;z-index:1" size="25" name="pw1" value="">
            <input type="password" id="Editbox2" style="position:absolute;left:100px;top:56px;width:250px;font-family:Courier New;font-size:16px;z-index:2" size="25" name="pw2" value="">
            </form>
            <script language="javascript"> 
            document.forms[0].onsubmit = function() 
            { 
            if 
            (this.elements['pw1'].value != this.elements['pw2'].value) 
            { 
            alert('Passwords do not match'); 
            return false; 
            } 
            
            return true; 
            } 
            </script></div>
            </body>
            </html>
            Last edited by Rems; 2nd October 2008, 21:21.

            Comment


            • #7
              Re: validate password length javascript

              thanks rems, the password validation but the password length still doesnt function

              Comment


              • #8
                Re: validate password length javascript

                Use just a single "onsubmit" action. One function and just one "return true;" for myForm

                Code:
                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                <html>
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                <title>Untitled Page</title>
                <script language="JavaScript" type="text/javascript">
                <!--
                function ValidatemyForm(TheForm)
                {
                 if (TheForm.Editbox1.value.length < 5)
                 {
                  alert("Please enter at least 5 characters in the \"Editbox1\" field.");
                  TheForm.Editbox1.focus();
                  return false;
                 }
                 if (TheForm.Editbox1.value != TheForm.Editbox2.value) 
                 { 
                  alert('Passwords do not match'); 
                  return false; 
                 } 
                return true;
                }
                //-->
                </script>
                </head>
                <body bgcolor="#FFFFFF" text="#000000">
                <div id="wb_Form1" style="position:absolute;left:42px;top:96px;width:398px;height:263px;z-index:3" align="left">
                <form name="myForm" method="post" action="feedback.php" id="Form1" onsubmit="return ValidatemyForm(this)">
                <input type="submit" id="Button1" name="Button1" value="Submit" style="position:absolute;left:154px;top:216px;width:96px;height:25px;font-family:Arial;font-size:13px;z-index:0">
                <input type="password" id="Editbox1" style="position:absolute;left:100px;top:19px;width:250px;font-family:Courier New;font-size:16px;z-index:1" size="25" name="pw1" value="">
                <input type="password" id="Editbox2" style="position:absolute;left:100px;top:56px;width:250px;font-family:Courier New;font-size:16px;z-index:2" size="25" name="pw2" value="">
                </form>
                </div>
                </body>
                </html>
                \Rems
                Last edited by Rems; 6th October 2008, 20:31.

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment


                • #9
                  Re: validate password length javascript

                  that works, but even when i do the exact thing in my register form, it doesnt work, thanks anyway mate, its obviously to complicated for me
                  Last edited by andysutils; 6th October 2008, 22:28.

                  Comment

                  Working...
                  X