JavaScript Verifying Passwords

The following script will verify and compare two passwords entered by the user.

Example

Choose a password:   Verify password:  

 

Script Source

<Under the head section>

<script language="javascript" type="text/javascript">

<!-- Hide script from old browsers

function validForm(passForm) {

if (passForm.passwd1.value =="") {
alert("You must enter a password")
passForm.passwd1.focus()
return false
}
if (passForm.passwd1.value !=.passForm.passwd2.value) {
alert("Entered passwords did not match")
passForm.passwd1.focus()
passForm.passwd1.select()
return false
}
return true
}

// Script by www.wizzardweb.co.uk
// If you are using this code please leave a link to www.wizzardweb.co.uk
// End hiding script -->

</script>

<Under the body section>

<form onsubmit="return validForm(this)" action="#">
Your Name:
<input type="text" size="30"/>&nbsp;
Choose a password:
<input type="password" name="passwd1" />&nbsp;
Verify password:
<input type="password" name="passwd2" />&nbsp;
<p><input type="submit" value="Submit" />&nbsp;<input type="reset" /></p>
</form>

 

Please let me know if this script was helpful to you.

[rating]