JavaScript Verifying Passwords

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


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")
return false
if (passForm.passwd1.value !=.passForm.passwd2.value) {
alert("Entered passwords did not match")
return false
return true

// Script by
// If you are using this code please leave a link to
// End hiding 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>


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