Skip to content

Commit

Permalink
Add maestro credit card detection
Browse files Browse the repository at this point in the history
  • Loading branch information
nosir committed Jul 23, 2016
1 parent 413140d commit 53e1d4f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"form",
"input"
],
"version": "0.4.11",
"version": "0.5.0",
"author": {
"name": "Max Huang",
"email": "[email protected]",
Expand Down
11 changes: 10 additions & 1 deletion dist/cleave-react.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/cleave-react.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ var CreditCardDetector = {
dankort: [4, 4, 4, 4],
instapayment: [4, 4, 4, 4],
jcb: [4, 4, 4, 4],
maestro: [4, 4, 4, 4],
visa: [4, 4, 4, 4],
generalLoose: [4, 4, 4, 4],
generalStrict: [4, 4, 4, 7]
Expand Down Expand Up @@ -446,6 +447,9 @@ var CreditCardDetector = {
// starts with 2131/1800/35; 16 digits
jcb: /^(?:2131|1800|35\d{0,2})\d{0,12}/,

// starts with 50/56-58/6304/67; 16 digits
maestro: /^(?:5[0678]\d{0,2}|6304|67\d{0,2})\d{0,12}/,

// starts with 4; 16 digits
visa: /^4\d{0,15}/
},
Expand Down Expand Up @@ -500,6 +504,11 @@ var CreditCardDetector = {
type: 'jcb',
blocks: blocks.jcb
};
} else if (re.maestro.test(value)) {
return {
type: 'maestro',
blocks: blocks.maestro
};
} else if (re.visa.test(value)) {
return {
type: 'visa',
Expand Down
4 changes: 2 additions & 2 deletions dist/cleave.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"form",
"input"
],
"version": "0.4.11",
"version": "0.5.0",
"author": {
"name": "Max Huang",
"url": "http://github.com/nosir",
Expand Down
9 changes: 9 additions & 0 deletions src/shortcuts/CreditCardDetector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var CreditCardDetector = {
dankort: [4, 4, 4, 4],
instapayment: [4, 4, 4, 4],
jcb: [4, 4, 4, 4],
maestro: [4, 4, 4, 4],
visa: [4, 4, 4, 4],
generalLoose: [4, 4, 4, 4],
generalStrict: [4, 4, 4, 7]
Expand Down Expand Up @@ -40,6 +41,9 @@ var CreditCardDetector = {
// starts with 2131/1800/35; 16 digits
jcb: /^(?:2131|1800|35\d{0,2})\d{0,12}/,

// starts with 50/56-58/6304/67; 16 digits
maestro: /^(?:5[0678]\d{0,2}|6304|67\d{0,2})\d{0,12}/,

// starts with 4; 16 digits
visa: /^4\d{0,15}/
},
Expand Down Expand Up @@ -94,6 +98,11 @@ var CreditCardDetector = {
type: 'jcb',
blocks: blocks.jcb
};
} else if (re.maestro.test(value)) {
return {
type: 'maestro',
blocks: blocks.maestro
};
} else if (re.visa.test(value)) {
return {
type: 'visa',
Expand Down
4 changes: 4 additions & 0 deletions test/CreditCardDetector_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ describe('CreditCardDetector', function () {
it('should match card ' + cardNumber, function () {
CreditCardDetector.getInfo(cardNumber, true).blocks.should.eql(CreditCardDetector.blocks[key]);
});

it('should match detected card type: ' + key, function () {
CreditCardDetector.getInfo(cardNumber, true).type.should.eql(key);
});
});
});
});
Expand Down
11 changes: 8 additions & 3 deletions test/fixtures/credit-card.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@
1800000000123456,
3500000000123456
],
"maestro": [
5000000000123456,
5600000000123456,
5700000000123456,
5800000000123456,
6304000000123456,
6700000000123456
],
"visa": [
4000000000123456
],
"generalStrict": [
2000000000000000000
]
}

0 comments on commit 53e1d4f

Please sign in to comment.