JavaScript Password Validation not working
<p>I am using this for my password matching but it is not working can anyone edit it please</p>

<pre><code> &lt;html&gt;
&lt;head&gt;

&lt;script type="text/javascript"&gt;
function validateFormOnSubmit(theForm) {
var reason = "";

reason += validatePassword(theForm.pw1);

if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  alert("All fields are filled correctly");
  return false;
}

function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 

    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a Password.\n";
    } else if ((fld.value.length &lt; 3) || (fld.value.length &gt; 15)) {
        error = "The Password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The Password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) &amp;&amp; (fld.value.search(/(0-9)+/)))) {
        error = "The Password must contain at least one numeral.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;

}  
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form onsubmit="return validateFormOnSubmit(this)" &gt;

&lt;table border=0&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;label for="pw1"&gt;Password:&lt;/label&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="password" name="pw1" size="20" id="password" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;label for="pw2"&gt;Confirm Password:&lt;/label&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="password" name="pw2" size="20" id="confPassword" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=2 align=center&gt;&lt;input type=submit value="Submit!"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>its working but i want to match the password also . but i am unable to do that how can do it? </p>
