1

I am using credit card swipe reader to get the credit card info on Web page. I am successful to get the info of credit card on Web page. But it is a long string and I get it in 1 field. I know I have to split it but I don't know how.

I have seen lot of examples on internet to splitting credit card string but the string I get is different than example so that's why I want help that can any body provide short javascript code for spliting this info?

<script type="text/javascript">
  function CreditCardswipe(){

  var card_data = "B4888940130123456^DOE/JOHN L^18022010000000000000000000000000002120010004888123456789123=18022010000012345678";
}

</script>
user2226181
  • 175
  • 5
  • 17
  • possible duplicate of [Parse Credit Card input from Magnetic Stripe](http://stackoverflow.com/questions/2121881/parse-credit-card-input-from-magnetic-stripe) – PaulG Apr 20 '15 at 10:43

2 Answers2

0

How about simple regex?

 output = card_data.split(/\^/);

That way you get

["B4888940130123456", 
 "DOE/JOHN L", 
 "18022010000000000000000000000000002120010004888123456789123=18022010000012345678"]

if you want the last one split too you can do once again

numbers = output[2].split(/\=/);

which will give you

  ["18022010000000000000000000000000002120010004888123456789123", 
   "18022010000012345678"]
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
0

I would recommend attempting to reformat the swipe data to be inline with most magstripe readers. Typically the track 1 begin is "%B" and end is "?", the track 2 is ";" and "?".

Swipe:
%B4003000123456781^DOE/JOHN L^151250254321987123456789012345?;4003000123456781=15125025432198712345?

Track 1:
%B4003000123456781^DOE/JOHN L^151250254321987123456789012345?

Track 2:
;4003000123456781=15125025432198712345?

Also, what data are you specifically attempting to get outside of the Name, Card Number and Exp? Those are typically all in track 1 for you.

Card #: 4888940130123456
Name: ^DOE/JOHN L^
Exp: 1802

Ian Link
  • 287
  • 2
  • 13