From 5f0c4a5de8fc33039f2da404c41ed7e9c91d7330 Mon Sep 17 00:00:00 2001 From: Ram Date: Mon, 26 Sep 2016 14:01:05 +0530 Subject: [PATCH 1/2] Bumping up Rupay (above Discover) --- package.json | 2 +- src/validator.js | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index cf7c975..8057e89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-card-validator", - "version": "1.0.6", + "version": "1.0.7", "description": "Card validation helpers for card number, expiry and CVV.", "main": "index.js", "scripts": { diff --git a/src/validator.js b/src/validator.js index 7a8f2a3..67cbc85 100644 --- a/src/validator.js +++ b/src/validator.js @@ -45,22 +45,30 @@ var cardTypes = [ pattern: /^(5018|5081|5044|5020|5038|603845|6304|6759|676[1-3]|6220|504834|504817|504645)\d*/, valid_length: [12, 13, 14, 15, 16, 17, 18, 19], cvv_length: [0, 3] - }, { - name: 'discover', - pattern: /^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/, - valid_length: [16], - cvv_length: [3] }, { name: 'rupay', range: [ - [508500, 508999], - [606985, 607984], - [608001, 608100], - [608101, 608500], - [652150, 653149] + [ [508500,508999], + [606985,607384], + [607385,607484], + [607485,607984], + [608001,608100], + [608101,608200], + [608201,608300], + [608301,608350], + [608351,608500], + [652150,652849], + [652850,653049], + [653050,653149]] ], valid_length: [16], cvv_length: [3] + }, + { + name: 'discover', + pattern: /^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/, + valid_length: [16], + cvv_length: [3] } ]; From e12ac2b5b551dc8558c4146982811359482b9e70 Mon Sep 17 00:00:00 2001 From: Ram Date: Mon, 26 Sep 2016 17:15:19 +0530 Subject: [PATCH 2/2] Updating the distribution --- dist/validator.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/validator.js b/dist/validator.js index 109283d..b391439 100644 --- a/dist/validator.js +++ b/dist/validator.js @@ -1,10 +1,10 @@ function cardValidator(t){return this.cardNumber=t,this.card=null,this.cardType="unknown",this.valid=!1,this.luhnValid=!1,this.lengthValid=!1,this.cvvLength=[],this.month=null,this.year=null,getCardType=function(t){var e,a -for(e=0,a=cardTypes.length;a>e;e++){if(cardTypes[e].hasOwnProperty("pattern")&&t.match(cardTypes[e].pattern))return cardTypes[e] +for(e=0,a=cardTypes.length;en;a=++n)e=h[a],e=+e,a%2?(e*=2,r+=10>e?e:e-9):r+=e +for(r=0,h=t.split("").reverse(),a=n=0,i=h.length;n=0},validateCardNumber=function(t){return this.card=getCardType(t),this.card&&this.cardType&&(this.cardType=this.card.name,this.luhnValid=isValidLuhn(t),this.lengthValid=isValidLength.call(this,t,this.card),this.cvvLength=this.card.cvv_length),{card_type:this.cardType,valid:this.luhnValid&&this.lengthValid,luhn_valid:this.luhnValid,length_valid:this.lengthValid,cvv_length:this.cvvLength}},normalize=function(t){return t.toString().replace(/[ -]/g,"")},this.getCardDetails=function(){if(!this.cardNumber)throw"Invalid cardNumber property set" var t=normalize(this.cardNumber) @@ -21,5 +21,5 @@ if(!t)throw"Expiry should not be empty" this.card||this.validateCard(),this.month&&this.year||this.setBaseDate(this.month,this.year) var a=t&&t.toString().split("/")||[void 0,void 0] if(!a[0]||!a[1]||isNaN(a[0])||isNaN(a[1]))throw"Expiry should be in MM/YYYY format" -return a&&2==a.length&&a[1]==this.year&&a[0]0&&parseInt(a[0])<13&&parseInt(a[1])>=this.year},this}var __indexOf=[].indexOf,cardTypes=[{name:"amex",pattern:/^3[47]/,valid_length:[15],cvv_length:[4]},{name:"diners_club_carte_blanche",pattern:/^30[0-5]/,valid_length:[14],cvv_length:[3]},{name:"diners_club_international",pattern:/^36/,valid_length:[14],cvv_length:[3]},{name:"jcb",pattern:/^35(2[89]|[3-8][0-9])/,valid_length:[16],cvv_length:[3]},{name:"laser",pattern:/^(6304|670[69]|6771)/,valid_length:[16,17,18,19]},{name:"visa_electron",pattern:/^(4026|417500|4508|4844|491(3|7))/,valid_length:[16],cvv_length:[3]},{name:"visa",pattern:/^4/,valid_length:[16],cvv_length:[3]},{name:"mastercard",pattern:/^5[1-5]/,valid_length:[16],cvv_length:[3]},{name:"maestro",pattern:/^(5018|5081|5044|5020|5038|603845|6304|6759|676[1-3]|6220|504834|504817|504645)\d*/,valid_length:[12,13,14,15,16,17,18,19],cvv_length:[0,3]},{name:"discover",pattern:/^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/,valid_length:[16],cvv_length:[3]},{name:"rupay",range:[[508500,508999],[606985,607984],[608001,608100],[608101,608500],[652150,653149]],valid_length:[16],cvv_length:[3]}] +return!(a&&2==a.length&&a[1]==this.year&&a[0]0&&parseInt(a[0])<13&&parseInt(a[1])>=this.year)},this}var __indexOf=[].indexOf,cardTypes=[{name:"amex",pattern:/^3[47]/,valid_length:[15],cvv_length:[4]},{name:"diners_club_carte_blanche",pattern:/^30[0-5]/,valid_length:[14],cvv_length:[3]},{name:"diners_club_international",pattern:/^36/,valid_length:[14],cvv_length:[3]},{name:"jcb",pattern:/^35(2[89]|[3-8][0-9])/,valid_length:[16],cvv_length:[3]},{name:"laser",pattern:/^(6304|670[69]|6771)/,valid_length:[16,17,18,19]},{name:"visa_electron",pattern:/^(4026|417500|4508|4844|491(3|7))/,valid_length:[16],cvv_length:[3]},{name:"visa",pattern:/^4/,valid_length:[16],cvv_length:[3]},{name:"mastercard",pattern:/^5[1-5]/,valid_length:[16],cvv_length:[3]},{name:"maestro",pattern:/^(5018|5081|5044|5020|5038|603845|6304|6759|676[1-3]|6220|504834|504817|504645)\d*/,valid_length:[12,13,14,15,16,17,18,19],cvv_length:[0,3]},{name:"rupay",range:[[[508500,508999],[606985,607384],[607385,607484],[607485,607984],[608001,608100],[608101,608200],[608201,608300],[608301,608350],[608351,608500],[652150,652849],[652850,653049],[653050,653149]]],valid_length:[16],cvv_length:[3]},{name:"discover",pattern:/^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/,valid_length:[16],cvv_length:[3]}] module.exports=cardValidator