Welcome to WebmasterWorld Guest from 54.158.52.166

Forum Moderators: open

Message Too Old, No Replies

password validation

     
5:22 pm on May 27, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 2, 2009
posts:79
votes: 0


I am new to Javascript ..

I want to validate my password in a signup form using Javascript ..and it should work in such a way that when the user enters a password and moves to the next form field (which is re-enter password), an alert box should come up if validation fails..

The logic that I have come up with is this....

<script type="text/javascript">
function passValid() {
var pass = document.getElementById("password").value;
var passLen = parseInt(pass.length);

if(passLen < 8) {
alert("Your password is too short. Please choose one atleast 8 characters long.";
}
}
</script>

and in the HTML form ...

<input type="password" name="password" id="password" value="" onChange="passValid();"/>

But this is not working..
Or can this be done only when the form is submitted?..
Is there any other event which can be used here?

7:07 am on May 28, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:July 5, 2008
posts:81
votes: 0


<input type="password" name="password" id="password" value="" onChange="passValid();"/>

Should read

<input type="password" name="password" id="password" value="" onchange="passValid();"/>

(the onchange has a small 'c')

1:21 pm on May 28, 2009 (gmt 0)

Preferred Member

10+ Year Member

joined:July 5, 2005
posts:352
votes: 0


At first glance, it appears that you're missing a closing " ) " on your alert.

alert("Your password is too short. Please choose one atleast 8 characters long.");

Although daveginorge is correct, it's not a make or break situation in this case.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members