title: JavaScript/jQuery VIN Validator
body: <p>Has anyone ever created a VIN Validator? I am trying to create a textbox where the user will enter in a Vehicle Identification Number and then JS/jQuery will validate if its correct or not in case they mistype the number. </p>
  
  <p>I am very new to JS/jQuery and have found some examples but of course have not been able to get them to work correctly... Any one with any ideas or suggestions it would be greatly appreciated, especially if you can tell me how to set up what I have below to work properly!</p>
  
  <p>Note: The <a href="http://www.cflib.org/index.cfm?event=page.udfbyid&amp;udfid=1710" rel="noreferrer">isVin() function</a>  is courtesy of <a href="http://www.cflib.org" rel="noreferrer">cflib.org</a></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;label name="vin"&gt;VIN&lt;/label&gt;
  &lt;input type="text" name="vin" /&gt;
  </code></pre>
  
  <p>ColdFusion:</p>
  
  <pre><code>&lt;cfscript&gt;
  /**
   * US Vehicle Identification Number (VIN) validation.
   * version 1.0 by Christopher Jordan
   * version 1.1 by RHPT, Peter Boughton &amp;amp; Adam Cameron (original function rejected valid VINs)
   * 
   * @param v      VIN to validate (Required)
   * @return Returns a boolean. 
   * @author Christopher Jordan (cjordan@placs.net) 
   * @version 1, February 19, 2013 
   */
  function isVIN(v) {
      var i = "";
      var d = "";
      var checkDigit = "";
      var sum = 0;
      var weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];
      var transliterations = {
          a = 1,    b = 2, c = 3, d = 4, e = 5, f = 6,    g = 7, h = 8,
          j = 1,    k = 2, l = 3, m = 4, n = 5,         p = 7,            r = 9,
                  s = 2, t = 3, u = 4, v = 5, w = 6,    x = 7, y = 8,    z = 9
      };
      var vinRegex = "(?x)    ## allow comments
          ^                    ## from the start of the string
                              ## see http://en.wikipedia.org/wiki/Vehicle_Identification_Number for VIN spec
          [A-Z\d]{3}            ## World Manufacturer Identifier (WMI)
          [A-Z\d]{5}            ## Vehicle decription section (VDS)
          [\dX]                ## Check digit
          [A-Z\d]                ## Model year
          [A-Z\d]                ## Plant
          \d{6}                ## Sequence
          $                    ## to the end of the string
      ";
  
      if (! REFindNoCase(vinRegex, arguments.v)) {
          return false;
      }
  
      for (i = 1; i &lt;= len(arguments.v); i++) {
          d = mid(arguments.v, i, 1);
  
          if (! isNumeric(d)) {
              sum += transliterations[d] * weights[i];
          } else {
              sum += d * weights[i];
          }
      }
  
      checkDigit = sum % 11;
  
      if (checkDigit == 10) {
          checkDigit = "x";
      }
      return checkDigit == mid(arguments.v, 9, 1);
  }
  &lt;/cfscript&gt;
  </code></pre>
  
  <p>Test Code:</p>
  
  <pre><code>    &lt;cfoutput&gt;
  &lt;cfset vin = "1GNDM19ZXRB170064"&gt;
  #vin#: #isVin(vin)#&lt;br /&gt;
  &lt;cfset vin = "1FAFP40634F172825"&gt;
  #vin#: #isVin(vin)#&lt;br /&gt;
  &lt;/cfoutput&gt;
  </code></pre>