2
Contributors
5
Replies
17
Views
4 Years
Discussion Span
Last Post by JorgeM
0

The first example is fine. If you want at least say 8 characters then...

if(userInput.length >= 8 { 

On that site, they show you two different approaches with regard to checking...

The first is basically whether the length is greater than min AND less than the max number. If the result is true then that's good. Else, take some action.

The second example is whether the length is less than the min or greater than the max. If the result is good, then that's bad. Take the appropriate action for non compliance.

0

echo "<tr><td><input type='submit' value='submit' onclick='stringlength(document.form1.text1,6,8)'></td></tr>";

& the file

function lengthRange(inputtxt, minlength, maxlength)  
{     
   var userInput = inputtxt.value;    
   if(userInput.length >= minlength && userInput.length <= maxlength)  
      {       
        return true;      
      }  
   else  
      {       
    alert("Please input between " +minlength+ " and " +maxlength+ " characters");         
        return false;     
      }    
}

Are not having any affect on my password input. Any idea?

0

Well, I've made some changes to your example, but you should note that the function you are calling and the name of the function in your script is different, so that's why nothing good or bad is happening in your case.

Try this..

<!DOCTYPE html>
<html>
<head>
 <title>Demo</title>
 <script>
 function validate(form, minlength, maxlength) {     
      var userInput = form.elements[0].value
      if(userInput.length >= minlength && userInput.length <= maxlength)  {       
        return true;      
      }  else  {       
         alert("Please input between " + minlength + " and " + maxlength + " characters");         
        return false;     
      }    
 }
 </script>

</head>
<body>
 <form id="form1" action="#" >
   <input type='text' /><br />
   <input type='submit' value='submit' onClick='return validate(this.form,6,8)'>
 </form>
</body>
</html>
0
if($row['password'] == $passwd)
        {
        echo "<html>";
        echo "<body>";
        echo "<script src='check.js'></script>";
        echo "<form id='form1' action='changepassword.php' method='post'>";
        echo "<table>";
        echo "<tr><td>";
        echo "New Password<center><input type='text' name='newpassword1'></td></tr></center>";
        echo "<tr><td>";
        echo "Re-Enter Password<center><input type='text' name='newpassword2'></td></tr></center>";
        echo "<tr><td><input type='submit' value='submit' onclick='return validate(this.form,6,8)'></td></tr>";
        echo "</table>";
        echo "</form>";
        echo "</body>";
        echo "</html>";
        }

What am I doing wrong?

function validate(form, minlength, maxlength) 
{
var userInput = form.elements[0].value

if(userInput.length >= minlength && userInput.length <= maxlength)
{
    return true;
}
else
{
    alert("Please input between " + minlength + " and " + maxlength + " characters");
return false;
}

}
0

You are missing a closing brace at the end of your javascript. If you use a web browser's dev tools, you can look at the errors generated in the console log.

I see that you started a new thread. Please try to complete one thread before you start another. I already replied in the other thread, otherwise it would have been deleted and we could have continued working with you here...

Here is the link for anyone else that if following this discussion..

http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/465310/java-script-password-length

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.