Skip to content

Commit 53e1d4f

Browse files
committed
Add maestro credit card detection
1 parent 413140d commit 53e1d4f

File tree

9 files changed

+46
-10
lines changed

9 files changed

+46
-10
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"form",
99
"input"
1010
],
11-
"version": "0.4.11",
11+
"version": "0.5.0",
1212
"author": {
1313
"name": "Max Huang",
1414
"email": "[email protected]",

dist/cleave-react.js

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cleave-react.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cleave.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ var CreditCardDetector = {
416416
dankort: [4, 4, 4, 4],
417417
instapayment: [4, 4, 4, 4],
418418
jcb: [4, 4, 4, 4],
419+
maestro: [4, 4, 4, 4],
419420
visa: [4, 4, 4, 4],
420421
generalLoose: [4, 4, 4, 4],
421422
generalStrict: [4, 4, 4, 7]
@@ -446,6 +447,9 @@ var CreditCardDetector = {
446447
// starts with 2131/1800/35; 16 digits
447448
jcb: /^(?:2131|1800|35\d{0,2})\d{0,12}/,
448449

450+
// starts with 50/56-58/6304/67; 16 digits
451+
maestro: /^(?:5[0678]\d{0,2}|6304|67\d{0,2})\d{0,12}/,
452+
449453
// starts with 4; 16 digits
450454
visa: /^4\d{0,15}/
451455
},
@@ -500,6 +504,11 @@ var CreditCardDetector = {
500504
type: 'jcb',
501505
blocks: blocks.jcb
502506
};
507+
} else if (re.maestro.test(value)) {
508+
return {
509+
type: 'maestro',
510+
blocks: blocks.maestro
511+
};
503512
} else if (re.visa.test(value)) {
504513
return {
505514
type: 'visa',

dist/cleave.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"form",
1111
"input"
1212
],
13-
"version": "0.4.11",
13+
"version": "0.5.0",
1414
"author": {
1515
"name": "Max Huang",
1616
"url": "http://github.com/nosir",

src/shortcuts/CreditCardDetector.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var CreditCardDetector = {
1010
dankort: [4, 4, 4, 4],
1111
instapayment: [4, 4, 4, 4],
1212
jcb: [4, 4, 4, 4],
13+
maestro: [4, 4, 4, 4],
1314
visa: [4, 4, 4, 4],
1415
generalLoose: [4, 4, 4, 4],
1516
generalStrict: [4, 4, 4, 7]
@@ -40,6 +41,9 @@ var CreditCardDetector = {
4041
// starts with 2131/1800/35; 16 digits
4142
jcb: /^(?:2131|1800|35\d{0,2})\d{0,12}/,
4243

44+
// starts with 50/56-58/6304/67; 16 digits
45+
maestro: /^(?:5[0678]\d{0,2}|6304|67\d{0,2})\d{0,12}/,
46+
4347
// starts with 4; 16 digits
4448
visa: /^4\d{0,15}/
4549
},
@@ -94,6 +98,11 @@ var CreditCardDetector = {
9498
type: 'jcb',
9599
blocks: blocks.jcb
96100
};
101+
} else if (re.maestro.test(value)) {
102+
return {
103+
type: 'maestro',
104+
blocks: blocks.maestro
105+
};
97106
} else if (re.visa.test(value)) {
98107
return {
99108
type: 'visa',

test/CreditCardDetector_spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ describe('CreditCardDetector', function () {
99
it('should match card ' + cardNumber, function () {
1010
CreditCardDetector.getInfo(cardNumber, true).blocks.should.eql(CreditCardDetector.blocks[key]);
1111
});
12+
13+
it('should match detected card type: ' + key, function () {
14+
CreditCardDetector.getInfo(cardNumber, true).type.should.eql(key);
15+
});
1216
});
1317
});
1418
});

test/fixtures/credit-card.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,15 @@
5656
1800000000123456,
5757
3500000000123456
5858
],
59+
"maestro": [
60+
5000000000123456,
61+
5600000000123456,
62+
5700000000123456,
63+
5800000000123456,
64+
6304000000123456,
65+
6700000000123456
66+
],
5967
"visa": [
6068
4000000000123456
61-
],
62-
"generalStrict": [
63-
2000000000000000000
6469
]
6570
}

0 commit comments

Comments
 (0)