title: Allow only space, underscore , alphabets and numbers in text box
body: <p>I have this code which allows all characters in a text box. It allows only alphabets and numbers as first character. Now, how do I allow only space and underscore along with alphabets and numbers? I want code only in jQuery. I found a similar solution over here but it doesn't contain jQuery code. <a href="http://jsfiddle.net/fwcfq/39/" rel="nofollow">http://jsfiddle.net/fwcfq/39/</a></p>
  
  <pre><code>    $('#value').bind('keypress', function(e) {
          if($('#value').val().length == 0){
              if (e.which == 32){//space bar
                  e.preventDefault();
              }
              var valid = (e.which &gt;= 48 &amp;&amp; e.which &lt;= 57) || (e.which &gt;= 65 &amp;&amp; e.which     &lt;= 90) || (e.which &gt;= 97 &amp;&amp; e.which &lt;= 122);
              if (!valid) {
                 e.preventDefault();
              }
          }
      }); 
  </code></pre>