Javascript Magstripe (track 1, track 2) data parser
Mar-22-2005 Modified by Wayne Walrath, Acme Technologies http://www.acmetech.com
based on demo source code from www.skipjack.com
HTML
<form>
<input type="text" id="hdnSwipeData" value="%5413330056003578=251210100017305672^CardUser/John^030510100000019301000000877000000?;1234123412341234=0305101193010877?">
<br />
<input type="button" value="Test Data" onclick="ParseParserObj()">
</form>
JavaScript
// /////////////////////////////////////////////////////////////////////////////////
// JavaScript Magstripe (track 1, track2) data parser object
//
// Mar-22-2005 Modified by Wayne Walrath,
// Acme Technologies http://www.acmetech.com
// based on demo source code from www.skipjack.com
//
// USAGE:
// var p = new SwipeParserObj();
// p.dump(); -- returns parsed field values and meta info.
// -- or --
// get individual field names (see member variables at top of object)
//
// if( p.hasTrack1 ){
// p.surname;
// p.firstname;
// p.account;
// p.exp_month + "/" + p.exp_year;
// }
///////////////////////////////////////////////////////////////////////////////////
function ParseParserObj()
{
var p = new SwipeParserObj( document.getElementById('hdnSwipeData').value );
if( p.hasTrack1 ){
p.account_name;
p.surname;
p.firstname;
p.account;
p.exp_month + "/" + p.exp_year;
}
alert("account_name: " + p.account_name + "\nsurname: " + p.surname + "\nfirstname: " + p.firstname + "\naccount: " + p.account+ "\nexpiration: " + p.exp_month + "/" + p.exp_year);
}
function SwipeParserObj(strParse)
{
///////////////////////////////////////////////////////////////
///////////////////// member variables ////////////////////////
this.input_trackdata_str = strParse;
this.account_name = null;
this.surname = null;
this.firstname = null;
this.acccount = null;
this.exp_month = null;
this.exp_year = null;
this.track1 = null;
this.track2 = null;
this.hasTrack1 = false;
this.hasTrack2 = false;
/////////////////////////// end member fields /////////////////
sTrackData = this.input_trackdata_str; //--- Get the track data
//-- Example: Track 1 & 2 Data
//-- %B1234123412341234^CardUser/John^030510100000019301000000877000000?;1234123412341234=0305101193010877?
//-- Key off of the presence of "^"...