title: Regular Expressions, Length check in Javascript
body: <p>I want to validate my form now, and I wrote some code, it's working perfectly for length constraints but I want to use Regular Expression to filter the values of each element. </p>
  
  <p>I found from a forum, these Regular Expressions:</p>
  
  <ul>
  <li><p>for Full Name: <code>var regex = /^[a-zA-Z ]$/;</code></p></li>
  <li><p>for Phone: <code>var regexPhone= /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/;</code></p></li>
  </ul>
  
  <p>I guess the HTML5 (input:type email) is enough for email validation</p>
  
  <p>Also I want to do this with the name, that when I type the full name, the first letters change to uppercase letters. For example--> input="john smith", changes to "John Smith".</p>
  
  <p>This is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function validateForm() {
  for (var i = 0; i &lt; document.forms[0].elements.length; i++) {
      var pedio = document.forms[0].elements[i];
   if(pedio.id.indexOf("Name")!=-1){
    if (pedio.value.length &lt; 5 || pedio.value.length &gt; 35) {
     alert("Full Name must be 5-35 character long");
              pedio.focus();
              pedio.style.backgroundColor = "#997379";
              return false;
    }
   }
   
      if ((pedio.id.indexOf("Phone") != -1) &amp;&amp; (isNaN(pedio.value))) {
          alert("Phone is must contain only numbers");
          pedio.focus();
          pedio.style.backgroundColor = "#997379";
          return false;
      }
   
   if(pedio.id.indexOf("Phone")!=-1){
    if (pedio.value.length!=10) {
     alert("Phone must be 10 numbers");
              pedio.focus();
              pedio.style.backgroundColor = "#997379";
              return false;
     }
    }
   }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>/* No CSS */</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;h1 class="Title"&gt;Sign Up&lt;/h1&gt;
  &lt;div&gt;
   &lt;form method="post" onsubmit="return validateForm()"&gt;
    &lt;input type="text" id="Name" name="yourname" placeholder="*Full Name" autocomplete="off" required&gt;
    &lt;input type="email" id="Email" name="youremail" placeholder="*E-Mail"autocomplete="off" required&gt;
    &lt;input type="tel" id="Phone" name="yourphone" placeholder="*Phone" autocomplete="off" required&gt;
    &lt;input type="password" id="Password" name="yourpassword" placeholder="*Password" autocomplete="off" required&gt;
    &lt;p class="signup"&gt; The fields with * are required!&lt;br&gt;
    -If you have an account, &lt;a class="signup" href="reservation.php"&gt;log in&lt;/a&gt; now-&lt;/p&gt;
  
    &lt;keygen name="security" style="display:none;"&gt;
    &lt;input type="submit" value="Register"&gt;
  
      &lt;/form&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>