title: Running an email regex test - .test() is not a function
body: <p>I'm doing a regex check valid email function and I get a vague error that it's not a function.</p>
  <p>These are the answers I referenced:</p>
  <p><em><a href="https://stackoverflow.com/questions/15060292/a-simple-jquery-form-validation-script">A simple jQuery form validation script</a></em></p>
  <p><em><a href="https://stackoverflow.com/questions/9572254/validate-email-with-regex-jquery">Validate email with a regex in jQuery</a></em></p>
  <p><em><a href="https://stackoverflow.com/questions/9552451/javascript-regexp-match-against-variable-email-domain/9552490#9552490">JavaScript regexp match against variable email domain</a></em></p>
  <p>The basic gist of the last two answers is to run a <code>.test()</code> running it against the email input. So from the third question I linked:</p>
  <pre><code>var userinput = 'dirk@something.com';
  var domain = 'somethingelse.com';
  
  var pattern = /^\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i
  if(!pattern.test(userinput) || userinput.split('@')[1] != domain)
  {
    alert('not a valid e-mailadres, or the wrong domain!');
  }​
  </code></pre>
  <p>I took this seemingly basic premise and ran with it.</p>
  <p>My code looks like this:</p>
  <p><strong>HTML:</strong></p>
  <pre><code>&lt;form action=&quot;/premium/sign-up/&quot; method=&quot;POST&quot; id=&quot;signupform&quot;&gt;
  
      &lt;div class=&quot;field&quot;&gt;
          &lt;input class=&quot;signup-form-input&quot; type=&quot;text&quot; name=&quot;name&quot; id=&quot;signupform-name&quot; &gt;
          &lt;label class=&quot;signup-form-input-label&quot; for=&quot;name&quot;&gt;Name&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class=&quot;field&quot;&gt;
          &lt;input class=&quot;signup-form-input&quot; type=&quot;text&quot; name=&quot;email&quot; id=&quot;signupform-email&quot; &gt;
          &lt;label class=&quot;signup-form-input-label&quot; for=&quot;email&quot;&gt;E-Mail&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class=&quot;field&quot;&gt;
          &lt;input class=&quot;signup-form-input&quot; type=&quot;password&quot; name=&quot;password&quot; id=&quot;signupform-password&quot; &gt;
          &lt;label class=&quot;signup-form-input-label&quot; for=&quot;Password&quot;&gt;Password&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class=&quot;field&quot;&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;_csrftoken&quot; value=&quot;&lt;%= token %&gt;&quot;&gt;
          &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Next&quot; class=&quot;signup-form-input&quot; id=&quot;signup-next&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;field field--lower-content&quot;&gt;
          &lt;input type=&quot;checkbox&quot; name=&quot;update-opt&quot; id=&quot;update-opt-checkbox&quot;&gt;
          &lt;label class=&quot;update-opt-label&quot; for=&quot;update-opt&quot;&gt;
              Sign up for updates from SparkNotes
          &lt;/label&gt;
          &lt;p&gt;By signing up, you agree to SparkNotes’s &lt;a href=&quot;/legal/&quot;&gt;Terms of Service&lt;/a&gt;
              , and &lt;a href=&quot;/legal/privacy/&quot;&gt;Privacy Policy&lt;/a&gt; &lt;/p&gt;
          &lt;p&gt;Already have an account? &lt;a href=&quot;/premium/login/&quot;&gt;Log in&lt;/a&gt; &lt;/p&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  <p><strong>JavaScript:</strong></p>
  <pre><code>$(function() {
      $(&quot;#signupform&quot;).submit(function(e) {
          var nameField = $(&quot;#signupform-name&quot;).val();
          var emailField = $(&quot;#signupform-email&quot;).val();
          var emailCheck = &quot;^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$&quot;;
          var passwordField = $(&quot;#signupform-pasword&quot;).val();
  
          if (nameField === &quot;&quot;) {
              e.preventDefault();
              $(&quot;#signupform-name&quot;).addClass(&quot;form-error&quot;);
          }
          if (!emailCheck.test(emailField)) {
              e.preventDefault();
              $(&quot;#signupform-email&quot;).addClass(&quot;form-error&quot;);
          }
          if (passwordField === &quot;&quot;) {
              e.preventDefault();
              $(&quot;#signupform-name&quot;).addClass(&quot;form-error&quot;);
          }
      });
  });
  </code></pre>
  <p>When I submit the form I get this:</p>
  <blockquote>
  <p>Uncaught TypeError: &quot;^w+([-+.']w+)<em>@w+([-.]w+)</em>.w+([-.]w+)*$&quot;.test is
  not a function <br/>
  at HTMLFormElement. (scripts.min.js:1) <br/>
  at HTMLFormElement.dispatch (jquery.min.js:2) <br/>
  at HTMLFormElement.y.handle (jquery.min.js:2)</p>
  </blockquote>
  <p>Why am I getting this? What am I doing wrong that the linked answers are doing right?</p>