title: how to sort mixed numeric/alphanumeric array in javascript
body: <p>I have a mixed array that I need to sort by number, alphabet and then by digit-</p>
  
  <pre><code>['A1', 'A10', 'A11', 'A12', 'A3A', 'A3B', 'A3', 'A4', 'B10', 'B2', 'F1', '1', '2', 'F3']
  </code></pre>
  
  <p>how do I sort it to be like:</p>
  
  <pre><code>['1', '2', 'A1', 'A2', 'A3', 'A3A', 'A3B', 'A4', 'A10', 'A11', 'A12', 'B2', 'B10', 'F1', 'F3']
  </code></pre>
  
  <p>Here is what I tried:</p>
  
  <pre><code>var reA = /[^a-zA-Z]/g;
  var reN = /[^0-9]/g;
  function sortAlphaNum(a, b) {
      var AInt = parseInt(a.Field, 10);
      var BInt = parseInt(b.Field, 10);
  
      if (isNaN(AInt) &amp;&amp; isNaN(BInt)) {
          var aA = (a.Field).replace(reA, "");
          var bA = (b.Field).replace(reA, "");
          if (aA === bA) {
              var aN = parseInt((a.Field).replace(reN, ""), 10);
              var bN = parseInt((b.Field).replace(reN, ""), 10);
              return aN === bN ? 0 : aN &gt; bN ? 1 : -1;
          } else {
              return aA &gt; bA ? 1 : -1;
          }
      } else if (isNaN(AInt)) {//A is not an Int
          return 1;//to make alphanumeric sort first return -1 here
      } else if (isNaN(BInt)) {//B is not an Int
          return -1;//to make alphanumeric sort first return 1 here
      } else {
          return AInt &gt; BInt ? 1 : -1;
      }
  }
  
  fieldselecteddata.sort(sortAlphaNum);
  </code></pre>
  
  <p>but that only sorts it alphabetically/numeric till combination of 1 numeric and 1 character like <code>A1</code>, <code>A2</code>, <code>A10</code>. But if there will be values like <code>A3A</code>, <code>A3B</code> in that case it wont sort properly. Can this be done with either straight JavaScript or jQuery?</p>