title: Not Allowing Whitespace With Javascript Validation
body: <p>I am working on a web form that must be validated on submit. I have a field for a first name that must follow two rules when validated, the name must have at least 3 letters and there can be no spaces between any of the characters. I have gotten it to display an error message when the name is too short, but I can't figure out how to not allow whitespace. </p>
  
  <p>How can I validate this so that there are no spaces between any characters using javascript?</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Project 5&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;form name="myForm" id="myForm" onsubmit="return validateForm()"&gt;
              First Name: &lt;input type="text" id="name"&gt; &lt;br&gt;
              Age: &lt;input type="text" id="age"&gt; &lt;br&gt;
              Street Address: &lt;input type="text" id="address"&gt; &lt;br&gt;
              State: &lt;select&gt;
                  &lt;option value="la"&gt;LA&lt;/option&gt;
                  &lt;option value="tx"&gt;TX&lt;/option&gt;
                  &lt;option value="ok"&gt;OK&lt;/option&gt;
                  &lt;option value="mi"&gt;MI&lt;/option&gt;
                  &lt;option value="az"&gt;AZ&lt;/option&gt;
              &lt;/select&gt; &lt;br&gt;
              Login Password: &lt;input type="password" id="password"&gt; &lt;br&gt;
              &lt;input type="submit" value="Submit"&gt; &lt;br&gt;
          &lt;/form&gt;
  
          &lt;script type="text/javascript"&gt;
              function validateForm() {
                  return checkName();
              }
  
              function checkName() {
                  var x = document.myForm;
                  var input = x.name.value;
                  if(input.length &lt; 3) {
                      alert("Please enter a name with at least 3 letters");
                      return false;
                  }
                  else if(input.length &gt;= 3) {
  
                  }
              }
  
          &lt;/script&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>