title: JavaScript: Unexpected outcome of character removal code
body: <p>My code is failing the test cases "should remove paren, spaces, hyphens, and dots" and "should validate when 11 digits and starting with 1 even with punctuation".</p>
  
  <p>It was previously passing the removal characters case then stopped after adding more stuff and I can't figure out what it is. The logs show pNum stripped of these characters but it's still failing?</p>
  
  <p>Help me debug? Here are the tests/results: <a href="https://puu.sh/ziot6/8982a12ad0.png" rel="nofollow noreferrer">https://puu.sh/ziot6/8982a12ad0.png</a></p>
  
  <pre><code>const phoneNumber = (pNum) =&gt; {
  
    var replaceChars = /[.)( -]/g;
  
    //removes parenthesis, spaces, hyphens, and dots
    pNum = pNum.replace(replaceChars,"");
    console.log(pNum);
  
    //returns pNum if length is 11 and starts with 1
    if (pNum.length == 11 &amp;&amp; pNum[0] == 1)
        return pNum;
  
    //returns pNum if length is 11 and starts with 1 and has punctuation
    if (pNum.length == 11 &amp;&amp; pNum[0] == 1 &amp;&amp; pNum.match(/\W/g))
        return pNum;
  
    //returns null if pNum is equal or less than 9 or more than 11
    if (pNum.length &lt;= 9 || pNum.length &gt; 11)
        return null;
  
    //returns null if pNum is 11 without 1 in the first index
    if (pNum.length == 11 &amp;&amp; pNum[0] !== 1)
        return null;
  
    //returns null if pNum has letters or punctuation and less than 11
    if (pNum.match(/[a-z]/i) &amp;&amp; pNum.length !== 11)
        return null;
  
    //return null when area code does not start 2-9
    if (pNum.length == 10 &amp;&amp; pNum[0] != ('2','3','4','5','6','7','8','9'))
        return null;
    if (pNum.length == 11 &amp;&amp; pNum[1] != ('2','3','4','5','6','7','8','9'))
        return null;
  
    //return null when exchange code does not start 2-9
    if (pNum.length == 10 &amp;&amp; pNum[3] != ('2','3','4','5','6','7','8','9'))
        return null;
    if (pNum.length == 11 &amp;&amp; pNum[4] != ('2','3','4','5','6','7','8','9'))
        return null;
  
  }
  </code></pre>