title: Jquery custom validator not working for Australian business number - ABN with mask
body: <p>I have been working on this for some time now and ended up resorting to <a href="https://jsfiddle.net/si2030/s6w94nxs/" rel="nofollow">jsfiddle</a> which is returning errors that I cant fix. Its giving this error:</p>
  
  <blockquote>
    <p>{"error": "Shell form does not validate{'html_initial_name':</p>
  </blockquote>
  
  <p>Apart from the jsFiddle problem the problem with the validator is the method was set to run through a pure number with no dashes. </p>
  
  <p>So I added a new variable which stripped out the dashes </p>
  
  <pre><code>var testValue = parseInt(value.replace(/-/g, ""));
  </code></pre>
  
  <p>but it giving an error or NaN - Not a number on the final Tally variable.</p>
  
  <p>What I wanted to do is apply a genuine ABN number in mask format eg 81-050-237-986 and process it with the method and get true.</p>
  
  <p>Here is the validator function:</p>
  
  <pre><code>      jQuery.validator.addMethod('abnValidate', function abnValidate(value, element) {
          if (value.length == 14) {
              var testValue = parseInt(value.replace(/-/g, ""));
              var weighting = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
              var tally = (parseInt(testValue[0]) - 1) * weighting[0];
              for (var i = 1; i &lt; testValue.length; i++) {
                  tally += (parseInt(value[i]) * weighting[i]);
              }
              return (tally % 89) == 0;
          }
          else {
              return true;
          }
      });
  
      $("#ABN").rules("add", {
          abnValidate: true,
          messages: {
              abnValidate: "The ABN does not conform to the ATO's algorithm"
          }
      });
  </code></pre>
  
  <p><b>EDIT</b>
  You can look at the formula the ATO uses is <a href="http://downloads.icbglobal.org/au/ATO/ATO_Format_of_the_ABN_NAT2956.pdf" rel="nofollow">here</a>.</p>
  
  <p>Basically the process is as follows:</p>
  
  <pre><code>To verify an ABN:
  To verify an ABN:
  1. Subtract 1 from the first (left) digit to give a new eleven digit number
  2. Multiply each of the digits in this new number by its weighting factor
  3. Sum the resulting 11 products
  4. Divide the total by 89, noting the remainder
  5. If the remainder is
  zero
  the number is valid
  </code></pre>