Link to home
Start Free TrialLog in
Avatar of jl66
jl66Flag for United States of America

asked on

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.
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
ASKER CERTIFIED SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jl66

ASKER

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.
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.
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jl66

ASKER

Thanks a lot.