validating phone number in Javascript with hyphens
<p>ok So I've tried to validate a phone number script for the past 2 hours but I can't seem to figure out why this isn't working. the Maximum length is 12 and I've already got an if statement for that, that works.</p>

<p>the format would have to be :   nnn-nnn-nnnn</p>

<pre><code>         var tele = document.pizza.field03;  //store phone number
         var fone = tele.value               //store values of variable tele in fone
         var acode = "";                    
         var midnum = "";                    
         var lasnum = "";                    
         var hyphen = "";                  
         var hyphen2 ="";                        

   acode=fone.substr(0,3);
   hyphen=fone.substr(3,4);
   midnum=fone.substr(4,7);
   hyphen2=fone.substr(7,8);
   lasnum=fone.substr(8);

       else if (isNaN(acode) )
         {
           errMessages += "&lt;li&gt;Please use integer numbers only&lt;/li&gt;\n";
           errMessages += "&lt;li&gt;ex: 1 2 3 4 5 &lt;/li&gt;\n";
         }

       else if (isNaN(midnum) )
         {
           errMessages += "&lt;li&gt;Please use integer numbers only&lt;/li&gt;\n";
           errMessages += "&lt;li&gt;ex: 1 2 3 4 5 &lt;/li&gt;\n";
         }

       else if (isNaN(lasnum) )
         {
           errMessages += "&lt;li&gt;Please use integer numbers only&lt;/li&gt;\n";
           errMessages += "&lt;li&gt;ex: 1 2 3 4 5 &lt;/li&gt;\n";
         }
</code></pre>

<p><em><strong>EDIT</em>*</strong></p>

<pre><code>else if (hyphen.indexOf('-') ==-1)                  //checking for hyphen
     {
       errMessages += "&lt;li&gt;You need a hyphen after the area code&lt;/li&gt;\n"
       errMessages += "&lt;li&gt;ex: areacode-nnn-nnn&lt;/li&gt;\n"
     }

   else if (hyphen2.indexOf('-') ==-1)
     {
       errMessages += "&lt;li&gt;You need a hyphen after the middle 3 digits&lt;/li&gt;\n";
       errMessages += "&lt;li&gt;ex: 416-mid-1234&lt;/li&gt;\n";
     }
</code></pre>

<p>what happens is whether I use digits or letters it'll keep popping up the error window.</p>

<p>I want to learn how to do this without using RegEx if possible.
Thank you.</p>
