title: Javascript name validation
body: <p>I have a javascript function written to validate a field on my form. This function is supposed to make sure the field is not empty, does not exceed the limit of 35 characters and only contains alphabetic characters and a hyphen(-). I had code to make sure the field is not empty and that it does not exceed 35 characters which worked fine but i added code to validate the field to the usable characters and i tested it out by leaving the field empty to make sure that still worked but when i hit the submit button the function didn't seem to validate at all, didn't give me an alert and just submitted. Here is my code: </p>
  
  <pre><code>function validateFamily()
  {
  var family=document.getElementById('family');
  var stringf = document.getElementById('family').value;
  if (family.value=="")
      {
       alert("Family name must be filled out");
       return false;
      }
  else if (document.getElementById('family').value.length &gt; 35)
      {
          alert("Family name cannot be more than 35 characters");
          return false;
      }
  else if (/[^a-zA-Z\-\]/.test( stringf ))
      {
          alert("Family name can only contain alphanumeric characters and hypehns(-)")
          return false;
      }
      return true;
  }
  
  &lt;form name="eoiform" method="POST" action="&lt;?php echo $_SERVER["PHP_SELF"];?&gt;" id="eoi" onsubmit="return validateFamily() &amp;&amp; validateGiven() &amp;&amp; validateMaleFemale() &amp;&amp; validDate() &amp;&amp; validateAddress() &amp;&amp; validatePost() &amp;&amp; validateParent() &amp;&amp; validateWork() &amp;&amp; validateHome() &amp;&amp; validateMob() &amp;&amp; validateCheckBoxes();"&gt;
  
  &lt;b&gt;Student's Family Name&lt;/b&gt; 
  &lt;br&gt;
  &lt;input type="text" id="family" name="family" /&gt;&lt;?php echo $strmsgf; ?&gt;
  
  &lt;input type="submit" name="submit" id="submit" value="submit" /&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Could anyone show me how to fix my code?</p>