title: jQuery form validation Regexp
body: <p>I am doing everything correct to validate username and password, still its not working. </p>
  
  <pre><code>&lt;script&gt;
  
  $(document).ready(function(){
      $('#username1').keyup(function() {
          $('span.error').hide();
          var inputVal = $(this).val();
          var usernameReg = /^[a-zA-Z0-9._-]{3,16}$/;
          if(!usernameReg.test(inputVal)) {
              $(this).after('&lt;span class="error"&gt;Username 3-16 characters long containing letters, numbers and underscore only.&lt;/span&gt;');
          }
      });
  
      $('#password1').keyup(function() {
          $('span.error').hide();
          var inputVal = $(this).val();
          var passwordReg = /^[A-Za-z0-9!@#$%^&amp;*()_]{6,16}$/;
          if(!passwordReg.test(inputVal)) {
              $(this).after('&lt;span class="error"&gt;Password must be atleast 6 characters long.&lt;/span&gt;');
          }
      });
  });
  
  &lt;/script&gt; 
  </code></pre>