title: How to validate form input text with javascript
body: <p>I'm trying to create a form with different inputs, input validation error receiving text, it does not validate (I want to be just text). The code is:</p>
  
  <pre><code>&lt;form action="" id="myform" name="checkform" onsubmit="return validateform()" method="post"&gt;
      &lt;label for='Name'&gt;Name:&lt;/label&gt;
      &lt;input type="text" name="name" id="name"&gt;&lt;br&gt;
      &lt;label for='Surname'&gt;Surname:&lt;/label&gt;
      &lt;input type="text" name="surname" &gt;&lt;br&gt; 
      &lt;input type="submit" name="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The javascript is:</p>
  
  <pre><code>   function validateform(){     
      if(document.checkform.name.value == ""){
          window.alert("Please insert your name.");
              document.checkform.name.focus();
              return false;
      }
      var nameText = document.forms["myform"]["name"].value; /* here is the problem :-( */
      if (!name.match(/^\s*[A-Za-z]+\s*$/)) {
      alert("Insert just letters !!!");
      return false;
      }
  }
  </code></pre>