Skip to content

Commit

Permalink
Merge pull request #672 from michaltk/more-creditcard-validator-fix
Browse files Browse the repository at this point in the history
Fix credit card validator to only remove dashes and spaces
  • Loading branch information
chriso authored Jun 29, 2017
2 parents 0d9ed49 + 678c39d commit a4d7157
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/isCreditCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][

function isCreditCard(str) {
(0, _assertString2.default)(str);
var sanitized = str.replace(/[^0-9]+/g, '');
var sanitized = str.replace(/[- ]+/g, '');
if (!creditCard.test(sanitized)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isCreditCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const creditCard = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9

export default function isCreditCard(str) {
assertString(str);
const sanitized = str.replace(/[^0-9]+/g, '');
const sanitized = str.replace(/[- ]+/g, '');
if (!creditCard.test(sanitized)) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,9 @@ describe('Validators', function () {
'2220175103860763',
'375556917985515999999993',
'899999996234917882863855',
'prefix6234917882863855',
'623491788middle2863855',
'6234917882863855suffix',
],
});
});
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][

function isCreditCard(str) {
assertString(str);
var sanitized = str.replace(/[^0-9]+/g, '');
var sanitized = str.replace(/[- ]+/g, '');
if (!creditCard.test(sanitized)) {
return false;
}
Expand Down
Loading

0 comments on commit a4d7157

Please sign in to comment.