title: How can I validate for whitespaces in textbox
body: <p>I am validating a text box using javascript, now what happens is that if the text box = '' or in other words is empty, then a message appears stating "Please Enter in a Room Number", if not then display an empty string "".</p>
  
  <p>Now this is fine if the text box is empty but if I type in a space or enter for example and then submit the form, then the validation message does not appear in this instance.</p>
  
  <p>How is it supposed to be coded so that if a textbox is empty of contains whitespaces, then it should display a message?</p>
  
  <p>Below is my code:</p>
  
  <pre><code>    &lt;head&gt;
              &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" /&gt;
              &lt;title&gt;Create a Session&lt;/title&gt;
              &lt;script type="text/javascript"&gt;
  
       function validation() {
      var roomTextO = document.getElementById("room");
      var errRoomMsgO = document.getElementById("roomAlert");
  
      if (roomTextO.value == ""){
                      errRoomMsgO.innerHTML = "Please Enter in a Room Number";
                  }else{
                      errRoomMsgO.innerHTML = ""; 
                  }  
  
              }
  
      &lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
  
      &lt;form action="create_session.php" method="post" name="sessionform"&gt;
  
      &lt;p&gt;&lt;strong&gt;8: Room:&lt;/strong&gt; &lt;input type="text" id="room"&gt;
  &lt;br/&gt;&lt;span id="roomAlert"&gt;&lt;/span&gt;&lt;/p&gt;      &lt;!-- Enter Room here--&gt;
  
      &lt;/form&gt;
      &lt;/body&gt;
  </code></pre>