title: How to add alphanumeric check to jQuery validation plugin?
body: <p>This exact question was asked here:</p>
  
  <p><a href="https://stackoverflow.com/questions/1053618/using-the-jquery-validation-plugin-how-can-i-add-a-regex-validation-on-a-textbox">using the jquery validation plugin, how can I add a regex validation on a textbox?</a></p>
  
  <p>But unfortunately the solution posted isn't working for me. I am using the very popular jquery validation plugin, specifically this version:</p>
  
  <p><a href="http://jquery.bassistance.de/validate/jquery.validate.js" rel="nofollow noreferrer">http://jquery.bassistance.de/validate/jquery.validate.js</a></p>
  
  <p>I tried adding the custom alphanumeric function (from the above stack overflow question) like so:</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://jquery.bassistance.de/validate/jquery.validate.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  $(function() {
  
      $.validator.addMethod("loginRegex", function(value, element) {
          return this.optional(element) || /^[a-z0-9\-]+$/i.test(value);
      }, "Username must contain only letters, numbers, or dashes.");
  
      $("#myForm").validate({
          rules: {
              "login": {
                  required: true,
                  loginRegex: true,
              }
          },
          messages: {
              "login": {
                  required: "You must enter a login name",
                  loginRegex: "Login format not valid"
              }
          }
      });
  
  });
  &lt;/script&gt;
  
  &lt;form method="post" id="myForm"&gt;
      &lt;input type="text" name="login" /&gt;  
      &lt;input type="submit" value="Go" /&gt;  
  &lt;/form&gt;
  </code></pre>
  
  <p>If you run this code you can see that it only validates for some type of input, it doesn't validate the input through the custom alphanumeric function. How can this be made to work?</p>