title: form validation using javascript,prevent submitting when errors occure
body: <p>I'm trying to apply form validation using js,the problem I'm facing is the form always submits no matter what errors are shown in the form.
  the form contains 6 fields: username,email,password,retype_pass, first_name,last_name.
  the js code is like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function checkForBlank() {
    $("#username_err_msg").hide();
    $("#email_err_msg").hide();
    $("#pwd_err_msg").hide();
    $("#confirm_pwd_err_msg").hide();
    $("#fname_err_msg").hide();
    $("#lname_err_msg").hide();
  
  
    var username_err = false;
    var email_err = false;
    var pwd_err_msg = false;
    var confirm_pwd_err_msg = false;
    var fname_err = false;
    var lname_err = false;
  
  
    $("#userName").focusout(function() {
      check_userName();
    });
    $("#inputEmail").focusout(function() {
      check_email();
  
    });
    $("#password").focusout(function() {
      check_pwd();
    });
    $("#inputConfirmPassword").focusout(function() {
      check_pwd_conf();
    });
    $("#inputFirstName").focusout(function() {
      check_fname();
    });
    $("#inputLastName").focusout(function() {
      check_lname();
    });
  
  
    function check_userName() {
      var username_length = $("#userName").val().length;
      if (username_length &lt; 5 || username_length &gt; 20) {
        $("#username_err_msg").html("Username must be between 5 and 20 characters ! ");
        $("#username_err_msg").show();
        username_err = true;
      } else {
        $("#username_err_msg").hide();
      }
    }
  
    function check_pwd() {
  
      var pass = $("#password").val();
      var pass_length = $("#password").val().length;
      var re = /^[a-zA-Z_0-9@\!#\$\^%&amp;*()+=\-[]\\\';,\.\/\{\}\|\":&lt;&gt;\? ]+$/;
      //if pwd is less than 10 and doesnt contain special chars
      if (pass_length &lt; 6) {
        $("#pwd_err_msg").html("Weak ! ");
        $("#pwd_err_msg").show();
        pwd_err_msg = true;
      } else {
        //if pwd is &gt;= 5 or &lt;= 10,and contains special char
        if (pass_length &gt;= 6 &amp;&amp; pass_length &lt; 9 &amp;&amp; !re.test(pass)) {
          $("#pwd_err_msg").html("Medium! ");
          $("#pwd_err_msg").show();
          pwd_err_msg = true;
        } else {
          //if pwd &gt;11 and contains special char
          if (pass_length &gt;= 9 &amp;&amp; !re.test(pass)) {
            $("#pwd_err_msg").html("Strong! ");
            $("#pwd_err_msg").show();
            pwd_err_msg = true;
          } else {
            $("#pwd_err_msg").hide();
          }
        }
      }
    }
  
    function check_pwd_conf() {
      var pass1 = $("#password").val();
      var pass2 = $("#inputConfirmPassword").val();
      if (pass1 != pass2) {
        $("#confirm_pwd_err_msg").html("Passwords don't match! ");
        $("#confirm_pwd_err_msg").show();
        pwd_err_msg = true;
      } else {
        $("#confirm_pwd_err_msg").hide();
      }
    }
  
    function check_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,}))$/;
      var email = $("#inputEmail").val();
      if (re.test(email)) //valid email address
      {
        $("#email_err_msg").hide();
      } else {
        $("#email_err_msg").html("Invalid email address!");
        $("#email_err_msg").show();
        email_err = true;
      }
    }
  
    function check_fname() {
      var fname_length = $("#inputFirstName").val().length;
      var first = $("#inputFirstName").val();
      var re = /\d/g;
      if (fname_length &lt;= 2 || fname_length &gt; 20) {
        $("#fname_err_msg").html("First name must be between 2 and 20 characters ! ");
        $("#fname_err_msg").show();
        fname_err = true;
      } else {
        if (re.test(first)) {
          $("#fname_err_msg").html("First name must not contain digits ! ");
          $("#fname_err_msg").show();
          fname_err = true;
        } else {
          $("#fname_err_msg").hide();
        }
      }
    }
  
    function check_lname() {
      var lname_length = $("#inputLastName").val().length;
      var sec = $("#inputLastName").val();
      var re = /\d/g;
      if (lname_length &lt;= 2 || lname_length &gt; 20) {
        $("#lname_err_msg").html("Last name must be between 2 and 20 characters ! ");
        $("#lname_err_msg").show();
        lname_err = true;
      } else {
        if (re.test(sec)) {
          $("#lname_err_msg").html("Last name must not contain digits ! ");
          $("#lname_err_msg").show();
          lname_err = true;
        } else {
          $("#lname_err_msg").hide();
        }
      }
    }
  
  });</code></pre>
  </div>
  </div>
  </p>