
JavaScript Verifying Passwords
The following script will verify and compare two passwords entered by the user.
Example
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"/>
Choose a password:
<input type="password" name="passwd1" />
Verify password:
<input type="password" name="passwd2" />
<p><input type="submit" value="Submit" /> <input type="reset" /></p>
</form>
Please let me know if this script was helpful to you.