title: Parsing Credit Card data from magnetic stripe reader using javascript
body: <p>Ok, So I have an html form that is displayed like so: </p>
  
  <pre><code>   &lt;span style='required'&gt;*&lt;/span&gt; - Indicates required field.
     &lt;div class='fields'&gt;Swiped Information&lt;/div&gt;
       &lt;input type=text name='swiped' id='swiped'&gt;
     &lt;/div&gt;
     &lt;div class='fields'&gt;First Name&lt;/div&gt;
      &lt;input type=text name='first_name' id='first_name'&gt;&lt;span style='required'&gt;*&lt;/span&gt;
     &lt;/div&gt;
     &lt;div class='fields'&gt;Last Name&lt;/div&gt;
      &lt;input type=text name='last_name' id='last_name'&gt;&lt;span style='required'&gt;*&lt;/span&gt;
     &lt;/div&gt;
     &lt;div class='fields'&gt;Expiration&lt;/div&gt;
      &lt;input type=text size=8 name='expiration' id='expiration'&gt;&lt;span style='required'&gt;*&lt;/span&gt;(MMYY)
     &lt;/div&gt;
     &lt;div class='fields'&gt;CVV Code&lt;/div&gt;
      &lt;input type=text size=8 name='cvv' id='cvv'&gt;&lt;span style='required'&gt;*&lt;/span&gt;
     &lt;/div&gt;
     &lt;div class='fields'&gt;Credit Card Number&lt;/div&gt;
      &lt;input type=text name='card' id='card'&gt;&lt;span style='required'&gt;*&lt;/span&gt;
     &lt;/div&gt;
     &lt;hr&gt;
     &lt;div class='buttons'&gt;&lt;/div&gt;
      &lt;a onclick="readCard();" style="cursor:pointer; color:red;"&gt;Swipe Credit Card&lt;/a&gt;
     &lt;/div&gt;
  </code></pre>
  
  <p>My knowledge of this kind of stuff is very poor. I have a basic little Credit Card Reader that plugs into my computer via USB. I am wanting to be able to swipe a credit card and have my website parse the information into the form fields that are above. </p>
  
  <p>I have added an <code>onclick=readCard();</code> event to a link below my form and when that is pushed java script is initiated to put focus on the <code>Swiped Information</code> field which will store the string of data from the magnetic stripe reader. </p>
  
  <pre><code>function readCard () {
  
     document.getElementById('swiped').focus();
  
  }
  </code></pre>
  
  <p>My thoughts would be that the employee would hit "Swipe Credit Card" which would make the Swiped Card Information field have focus and would fill that field with the string, then the javascript would break that information up into pieces and fill the form accordingly. </p>
  
  <p>I have searched high and low to try and find a solution and the closest I could come was a tutorial that used asp.net as the language and I can't do that. Either PHP or JavaScript. Thanks in advance.</p>
  
  <p>All I need to do is break that long string up into multiple and display the appropriate parts in the html form.</p>
  
  <p>P.S. I'm not worried about form validation ATM, I will be taking care of that after I manage to make it fill the form fields! Thanks!</p>
  
  <p>UPDATE: </p>
  
  <p>I created a JSFiddle although the java script I put in doesn't appear to be working. 
  <a href="http://jsfiddle.net/r8FJX/" rel="nofollow">http://jsfiddle.net/r8FJX/</a></p>
  
  <p>UPDATE: </p>
  
  <p>As per the comments below, I have added an example of the data sent from my card reader to the computer. I went in and replaced every number in the string with randomly typed fake numbers and replaced my name with a fake one. (Sorry scammers!)</p>
  
  <pre><code>%B6545461234613451^DOE/JOHN^00000000000000000000000?;6545461234613451=984651465116111?
  </code></pre>
  
  <p>I am assuming this how the code above is laid out, I can't find any documentation: </p>
  
  <pre><code>%Bcardnumber^lastname/firstname^expDate?;cardnumber=expDate?
  </code></pre>