title: RegEx Vin Validation for pre 1980 and post 1980
body: <p>In 1981, Vehicle Identification Numbers (VINs) were standardized using a seventeen digit system. Prior to 1981, manufacturers used VINs unique to their own company and there was no accepted standard for these numbers, so different manufacturers used different formats..
  <a href="http://www.crankshaftcoalition.com/wiki/VIN_decoding" rel="nofollow noreferrer">http://www.crankshaftcoalition.com/wiki/VIN_decoding</a></p>
  
  <p>It required all over-the-road-vehicles sold to contain a 17-character VIN, which does not include the letters I (i), O (o), or Q (q) (to avoid confusion with numerals 1 and 0).
  <a href="http://en.wikipedia.org/wiki/Vehicle_identification_number" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Vehicle_identification_number</a></p>
  
  <p>So what I am trying to accomplish is having a drop down and if anywhere from 1980 - 1900 is chosen the VIN will either follow the guidelines of the manufactures or just not apply at all where the letters I (i), O (o), or Q (q) could be used and any number of characters/numbers. But then if 1981 and later is chosen the RegEx to kick in and demand it to be formatted with the Expression that I have showing a valid or invalid VIN.</p>
  
  <p>Plugged a valid VIN in for the time being for testing purposes.. if you delete the last number it will show "Invalid Vin"</p>
  
  <p>Any suggestions or help would be greatly appreciated! </p>
  
  <p><a href="http://jsfiddle.net/ommLz4th/1/" rel="nofollow noreferrer">http://jsfiddle.net/ommLz4th/1/</a></p>
  
  <p>RegExp</p>
  
  <pre><code>^[A-HJ-NPR-Z\\d]{8}[\\dX][A-HJ-NPR-Z\\d]{2}\\d{6}$
  </code></pre>
  
  <p>jQuery Vin Validator</p>
  
  <pre><code>    $(function() {
    $("#vin").on("keyup blur", function() {
      if (validateVin($("#vin").val())) {
        $("#result").css('color', 'green').html("Valid VIN");
        $("#vin").removeClass("not-ok").addClass("ok");
      } else {
        $("#result").css('color', 'red').html("Invalid VIN");
        $("#vin").removeClass("ok").addClass("not-ok");
      }
    });
  });
  
  
  function validateVin(vin) {
    var re = new RegExp("^[A-HJ-NPR-Z\\d]{8}[\\dX][A-HJ-NPR-Z\\d]{2}\\d{6}$");
    return vin.match(re);
  }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;label name="vin"&gt;VIN&lt;/label&gt;
  &lt;input type="text" id="vin" value="1FAFP40634F172825" /&gt;
  &lt;span id="result"&gt;&lt;/span&gt;
  </code></pre>
  
  <p>Drop Down for test purposes</p>
  
  <pre><code>&lt;select name="vehicleyear" id="vehicleyear"&gt;
      &lt;option value=""&gt;Choose Year&lt;/option&gt;
      &lt;option value="1985"&gt;1985&lt;/option&gt;
      &lt;option value="1984"&gt;1984&lt;/option&gt;
      &lt;option value="1983"&gt;1983&lt;/option&gt;
      &lt;option value="1982"&gt;1982&lt;/option&gt;
      &lt;option value="1981"&gt;1981&lt;/option&gt;
      &lt;option value="1980"&gt;1980&lt;/option&gt;
      &lt;option value="1979"&gt;1979&lt;/option&gt;
      &lt;option value="1978"&gt;1978&lt;/option&gt;
      &lt;option value="1977"&gt;1977&lt;/option&gt;
      &lt;option value="1976"&gt;1976&lt;/option&gt;
      &lt;option value="1975"&gt;1975&lt;/option&gt;
      &lt;option value="1974"&gt;1974&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Actual Drop down</p>
  
  <pre><code>&lt;cfparam name="form.vehicleyear" default=""&gt;
  
  &lt;cfset VARIABLES.y1=DatePart("yyyy",Now())&gt;
  &lt;cfset VARIABLES.y2=VARIABLES.y1+2&gt;
  
  &lt;cfif Val(form.vehicleyear) LT VARIABLES.y1 or Val(form.vehicleyear) GT VARIABLES.y2&gt;
  &lt;/cfif&gt;
  
   &lt;cfoutput&gt;
      &lt;cfselect name="vehicleyear" id="vehicleyear" required="yes" message="Please select vehicle year."&gt;
      &lt;option value="" selected="selected"&gt;Select Year&lt;/option&gt;
      &lt;cfloop index="i" from="#VARIABLES.y2#" to="1900" step="-1"&gt;
      &lt;option value="#i#"&lt;cfif form.vehicleyear EQ i&gt; selected&lt;/cfif&gt;&gt;#NumberFormat(i,"0000")#&lt;/option&gt;
      &lt;/cfloop&gt;
      &lt;/cfselect&gt;
   &lt;/cfoutput&gt;
  </code></pre>