how to implement javascript to validate the password in a web site?

Can any gurus quickly show me the steps to implement a function to validate the password into a web site with java script? For example, I only need to restrict the password can not be shorter than 6.
jl66Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee SavidgeCommented:
I'd use the onkeydown event and check the string length.

<input type=password onkeydown=checkLength(this.value)>

<input type=submit disabled id=submitButton value=Submit>

<script>
function checkLength(sPassword)
{
  if(sPassword.length>=6)
    document.getElementById("submitButton").disabled = false;
}
</script>

Open in new window


The code may not be right but I have written from memory and not tested but you get the idea.
0
Lee SavidgeCommented:
Improved a bit and tested

<html>
<body>

<input type=password onkeydown=checkLength(this.value)>

<input type=submit disabled id=submitButton value=Submit>

<script>
function checkLength(sPassword)
{
  if(sPassword.length>=6)
    document.getElementById("submitButton").disabled = false;
  else
    document.getElementById("submitButton").disabled = true;

}
</script>

</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jl66Author Commented:
Thanks a lot for the tip/function. I am a newbie for this web dev. Can you tell me where I should place the code in? The more detailed, more better. Appreciate it in advance.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Lee SavidgeCommented:
Copy and paste the second piece of code I did, and save it as an HTML file. Put the file in a virtual folder under IIS and then go to your browser and open the URL to that file and it will work. The code I did is the most basic I could get it. If you need help setting up a website to view the file, that's a different question altogether.

If you haven't got a website/virtual folder to put it in, just put it in a folder and right click and open with Internet Explorer. It might ask you if you want to allow the active content to run but you just say yes.
0
Lee SavidgeCommented:
Just a minor point, but you've posted in the Javascript, Web Development and Java topic areas. Java and Javascript are completely different languages and not related to each other. Your questions isn't related to Java so it shouldn't be in that zone.
0
gurpsbassiCommented:
Doing password validation on the client side has disadvantages too. Anyone can view your JavaScript source. Now they can see your password validation rules. This can be used in the wrong way by a hacker.
0
jl66Author Commented:
Thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.