Forum Moderators: open

Message Too Old, No Replies

password validation

         

naiquevin

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

10+ Year Member



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?

daveginorge

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

10+ Year Member



<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')

Trace

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

10+ Year Member



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.