Identify merchant provider from the given credit card no.
Hi Friends,
I was working on the financial application, where the user doesn’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 var cards = new Array(); cards [0] = {cardName: "Visa",prefixes: "4"}; cards [1] = {cardName: "Mastercard", prefixes: "51,52,53,54,55"}; cards [2] = {cardName: "DinersClub", prefixes: "300,301,302,303,304,305,36,38,55"}; cards [3] = {cardName: "CarteBlanche", prefixes: "300,301,302,303,304,305,36,38"}; cards [4] = {cardName: "American Express", prefixes: "34,37"}; cards [5] = {cardName: "Discovery", prefixes: "6011,650"}; cards [6] = {cardName: "JCB", prefixes: "3,1800,2131"}; cards [7] = {cardName: "enRoute", prefixes: "2014,2149"}; cards [8] = {cardName: "Solo", prefixes: "6334, 6767"}; cards [9] = {cardName: "Switch", prefixes: "4903,4905,4911,4936,564182,633110,6333,6759"}; cards [10] = {cardName: "Maestro", prefixes: "5020,6"}; cards [11] = {cardName: "VisaElectron", prefixes: "417500,4917,4913"}; var prefix var cardType for(cardType=0; cardType<cards.length; cardType++){ prefix = cards[cardType].prefixes.split(","); for (i=0; i<prefix.length; i++) { var exp = new RegExp ("^" + prefix[i]); if (exp.test (cardNo)) return cards[cardType].cardName; } } return "Invalid"; }
The above function returns merchant provider name if matching pattern is found and Invalid if not. Please make a note, this function doesn’t validates the credit card no.
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 http://www.ihwy.com/labs/jquery-validate-credit-card-extension.aspx
Thanks!
~~Amit Jain~~
amit@intelligrape.com
IntelliGrape Softwares