Validating forms using javascript only and preventing users from submitting JS disabled forms?
<p>I am trying to create a validated registration form for my website and am currently coding up a demo of it for practice. I was able to validate the form using javascript. However, I read somewhere that forms should be validated both client and server side because JS can be disabled. I was wondering if there is a way to simply disable the submit button if all javascript validations aren't satisfied (I noticed that eBay uses a similar method with their registration forms) and if so, how would I go about accomplishing this?</p>

<p>This is where I am at so far:</p>

<pre><code>&lt;script type="text/javascript"&gt;
function validateEmail(email) { 

    var re = /^(([^&lt;&gt;()[\]\\.,;:\s@\"]+(\.[^&lt;&gt;()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

    if(re.test(email)) {
        document.getElementById('result').innerHTML = '&lt;img src="http://iconlet.com/icons/kensaunders/4/CheckMark.png" style="width:15px;"/&gt; Valid';
    } else {
        document.getElementById('result').innerHTML = '&lt;img src="http://biglistbigsales.com/m/templates/GPT/images/x_xMarkRed4.png" style="width:15px;"/&gt; Invalid';
    }
} 
function validatePass(pass){
    if(pass.length &lt; 6){
        document.getElementById('pass-result').innerHTML='&lt;img src="http://biglistbigsales.com/m/templates/GPT/images/x_xMarkRed4.png" style="width:15px;"/&gt;Your password must be at least 6 characters';
    }else{
        document.getElementById('pass-result').innerHTML='&lt;img src="http://iconlet.com/icons/kensaunders/4/CheckMark.png" style="width:15px;"/&gt;valid';
    }
}
function validateCPass(cpass){
    var pass = document.getElementById('pass').value;

    if(cpass != pass){
        document.getElementById('cpass-result').innerHTML="Passwords must match";
    }else{
        document.getElementById('cpass-result').innerHTML='&lt;img src="http://iconlet.com/icons/kensaunders/4/CheckMark.png" style="width:15px;"/&gt;';
    }   
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form action="practice.php" method="post"&gt;
        e-mail:&lt;br/&gt;&lt;input id="email" type="text" onblur="validateEmail(this.value)" /&gt;&lt;span id="result"&gt;&lt;/span&gt;
        &lt;br/&gt;&lt;br/&gt;Password:&lt;br/&gt;&lt;input type="password" id="pass" onblur="validatePass(this.value)"&gt;&lt;span id="pass-result"&gt; &lt;/span&gt;
        &lt;br/&gt;&lt;br/&gt;Confirm Password:&lt;br/&gt;&lt;input type="password" id="confpass" onblur="validateCPass(this.value)"&gt; &lt;span id="cpass-result"&gt;&lt;/span&gt;
        &lt;br/&gt;&lt;input type="submit"&gt;
    &lt;/form&gt;
&lt;/body&gt;
</code></pre>
