title: Javascript phone number validation
body: <p>I need to validate a phone number in javascript.
  The requirements are:</p>
  
  <blockquote>
    <p>they should be 10 digits, no comma, no
    dashes, just the numbers, and not the
    1+ in front</p>
  </blockquote>
  
  <p>this is what I wrote so far</p>
  
  <pre><code>function validatePhone(field,alerttxt) {
      with (field) {
          if(value.length &gt; 10) {
              alert(alerttext);
              return false;
          }
          for(i = 0; i &lt; value.length; i++) {
              if(parseInt(value[i]) == NaN) {
                  alert(alerttxt);
                  return false;
              }
          }
          return true;
      }
  }
  function validateForm(thisform) {
          if (validatePhone(phone,"Invalid phone number")==false) {
              phone.focus();
              return false;
          }
  
      }
  }
    &lt;form action="post.php" method="post" id="contactform" onsubmit="return validateForm(this)"&gt;
      &lt;ol&gt;
          &lt;label for="phone"&gt;Your phone &lt;span class="red"&gt;&lt;/span&gt;&lt;/label&gt;
          &lt;input id="phone" name="phone" class="text" /&gt;
        &lt;/li&gt;
      &lt;/ol&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>but, obviously it doesn't work.
  How can I write the <code>validatePhone()</code> function so that it works?</p>