Magnetic Track Data Parsers
Parsing Mag Stripe Track Data
I had to write some code to parse mag stripe track data (as found on credit and debit cards) recently, and since pre-written parsers in Java and JavaScript were not easy to locate, I’m making mine available here. For more information on Track 1 and Track 2 data, please see the background document: Magnetic Stripe Track 1, Track 2 Data Description.
Parsing Magnetic Track Data in Java
The CreditCardUtils.jar file contains Java classes for parsing magnetic track data (tracks 1 and 2), validating credit card account numbers (LUHN checksum) and determining the type of credit card (e.g., AmEx, Visa, MasterCard, Discover, etc.).
- View the JavaDocs for the credit card validation and parsing utilities
- Download the CreditCardUtils.jar
The java archive contains the following classes:
- com/acmetech/cc/CreditCardInfo.java
- com/acmetech/cc/MagStripeCard.java
- com/acmetech/cc/MagstripeParseException.java
The track data parser accepts as input, track 1 (with or without sentinels), track 2 (with or without sentinels) or combined Track 1 and Track 2 strings. It will canonicalize the input track data, optionally auto-generate Track 2 string data when only Track 1 is provided, and offers functions for obtaining raw tracks, account holder name, expiration date, and primary account number.
Parsing Mag Stripe Track Data in JavaScript
I’ve cobled together a JavaScript object from sources found at www.skipjack.com for parsing magnetic track data. Usage involves first creating a new object seeded with your track data:
var track = "%B1234123412341234^Carduser/John^";
track += "030510100000019301000000877000000?";
track += ";1234123412341234=0305101193010877?";
var p = new SwipeParserObj(track);
To view the parsed fields, use the dump() function of the object:
p.dump(); -- returns parsed field values and meta info.
– or –
get individual field names (see member variables at top of MyMagstripeParser object definition):
if( p.hasTrack1 ){
p.surname;
p.firstname;
p.account;
p.exp_month + \"/\" + p.exp_year;
}
View or Download JavaScript Track 1 and 2 Parser
When I get more time, I’ll create an online form for testing these functions. For now that exercise is left to the reader.

