{"id":277,"date":"2009-11-04T00:47:25","date_gmt":"2009-11-03T19:17:25","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=277"},"modified":"2010-06-09T15:51:37","modified_gmt":"2010-06-09T10:21:37","slug":"identify-merchant-provider-from-the-given-credit-card-no","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/identify-merchant-provider-from-the-given-credit-card-no\/","title":{"rendered":"Identify merchant provider from the given credit card no."},"content":{"rendered":"<p>Hi Friends,<\/p>\n<p>I was working on the financial application, where the user doesn&#8217;t want to select merchant provider while feeding in credit card details and yet we needed to know the merchant provider. Following is the code that helped:<\/p>\n<blockquote>\n<div class=\"wp_syntax\">\n<div class=\"code\">\n<pre class=\"javascript\"> \r\nfunction getMerchantProvider(cardNo){                      \/\/cardNo is the credit card number\r\n\u00a0\u00a0\u00a0 var cards = new Array();\r\n    cards [0] = {cardName: \"Visa\",prefixes: \"4\"};\r\n\u00a0   cards [1] = {cardName: \"Mastercard\", prefixes: \"51,52,53,54,55\"};\r\n\u00a0   cards [2] = {cardName: \"DinersClub\", prefixes: \"300,301,302,303,304,305,36,38,55\"};\r\n\u00a0   cards [3] = {cardName: \"CarteBlanche\", prefixes: \"300,301,302,303,304,305,36,38\"};\r\n\u00a0   cards [4] = {cardName: \"American Express\", prefixes: \"34,37\"};\r\n\u00a0   cards [5] = {cardName: \"Discovery\",\u00a0 prefixes: \"6011,650\"};\r\n\u00a0   cards [6] = {cardName: \"JCB\", prefixes: \"3,1800,2131\"};\r\n\u00a0   cards [7] = {cardName: \"enRoute\", prefixes: \"2014,2149\"};\r\n\u00a0   cards [8] = {cardName: \"Solo\", prefixes: \"6334, 6767\"};\r\n\u00a0   cards [9] = {cardName: \"Switch\", prefixes: \"4903,4905,4911,4936,564182,633110,6333,6759\"};\r\n\u00a0   cards [10] = {cardName: \"Maestro\", prefixes: \"5020,6\"};\r\n\u00a0   cards [11] = {cardName: \"VisaElectron\", prefixes: \"417500,4917,4913\"};\r\n\u00a0\u00a0\u00a0 var prefix\r\n\u00a0\u00a0\u00a0 var cardType\r\n\r\n\u00a0\u00a0\u00a0 for(cardType=0; cardType&lt;cards.length; cardType++){\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = cards[cardType].prefixes.split(\",\");\r\n\u00a0\u00a0\u00a0\u00a0    for (i=0; i&lt;prefix.length; i++) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0        var exp = new RegExp (\"^\" + prefix[i]);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0        if (exp.test (cardNo))\r\n                  return cards[cardType].cardName;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0      \r\n   \u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0 return \"Invalid\";\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n}\r\n<\/pre>\n<\/div>\n<\/div>\n<\/blockquote>\n<p>The above function returns merchant provider name if matching pattern is found and Invalid if not. Please make a note, this function doesn&#8217;t validates the credit card no.<\/p>\n<p>For the credit card number validation I used jquery extended validation plugin for credit card, which also needed to know the merchant provider for validation so this code helped. Extended credit card validation plugin can be found at <a href=\"http:\/\/www.ihwy.com\/labs\/jquery-validate-credit-card-extension.aspx\">http:\/\/www.ihwy.com\/labs\/jquery-validate-credit-card-extension.aspx<\/a><\/p>\n<p>Thanks!<\/p>\n<p>~~Amit Jain~~<br \/>\n<a href=\"mailto:amit@intelligrape.com\">amit@intelligrape.com<\/a><br \/>\nIntelliGrape Softwares<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi Friends, I was working on the financial application, where the user doesn&#8217;t want to select merchant provider while feeding in credit card details and yet we needed to know the merchant provider. Following is the code that helped: function getMerchantProvider(cardNo){ \/\/cardNo is the credit card number \u00a0\u00a0\u00a0 var cards = new Array(); cards [0] [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[1],"tags":[139,55,141,27,140],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/277"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=277"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/277\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}