Skip to content

Commit

Permalink
add 4 digit support for amex
Browse files Browse the repository at this point in the history
  • Loading branch information
beganovich committed Oct 22, 2024
1 parent 30116b0 commit cf52975
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ export class SimpleCard {
);

new Maskito(this.cvv as MaskitoElement, {
mask: [/\d/, /\d/, /\d/],
mask: () => {
if (this.type() === "amex") {
return [/\d/, /\d/, /\d/, /\d/];
}

return [/\d/, /\d/, /\d/];
},
});
}

Expand All @@ -201,7 +207,10 @@ export class SimpleCard {
this.date.value
);

const cvv = new RegExp("^\\d{3}$").test(this.cvv.value);
const cvv =
this.type() === "amex"
? new RegExp("^[0-9]{4}$").test(this.cvv.value)
: new RegExp("^[0-9]{3}$").test(this.cvv.value);

return {
valid: number && date && cvv,
Expand Down

0 comments on commit cf52975

Please sign in to comment.