title: TypeError: pattern.test is not a function
body: <p>I'm writing a register form which has a ton of javascript included. While writing the basic functions to check the format of certain strings, I came across this problem (I've tried to solve it by myself but no luck there). In this simplified version I have three functions: one to check the format of phone number, second to check the format of email and third to combine those two functions to make it more clear. Here's the code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;script&gt;
          function filterPhone(phone){
              var pattern = "/^(()?\d{3}())?(-|\s)?\d{3}(-|\s)?\d{4}$/";
              return pattern.test(phone);
          }
  
          function filterEmail(email) {
              var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
              return regex.test(email);
          }
  
          function checkForm(){
              var puh = document.getElementById("puh").value;
          var email = document.getElementById("email").value;
              if(filterPhone(puh) &amp;&amp; filterEmail(email)){
                  alert("It works");
                  return true;
              } else {
                  alert("Check the format!");
                  return false;
              }
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form method="post" action="" name="regForm" onsubmit="return checkForm()"&gt;
      &lt;input type="text" name="puh" id="puh" placeholder="Phonenumber"&gt;&lt;br&gt;
      &lt;input type="text" name="email" id="email" placeholder="Email address"&gt;&lt;br&gt;
      &lt;input type="submit" value="Check!"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>If I only use the function filterEmail it works fine but when I use them both (or even only the filterPhone!) it gives me an error: <strong>"TypeError: pattern.test is not a function"</strong> ("pattern" referring to the first function's (filterPhone) variable name called pattern). I've tried using exec() instead of test() and changing the regex-pattern, neither have worked. This is rather weird since the syntax seems to be correct. Why could be the reason?</p>