Skip to content

Instantly share code, notes, and snippets.

@larchanka
Last active September 15, 2017 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larchanka/97f8e61ab1c604bb1caafc4247e7595e to your computer and use it in GitHub Desktop.
Save larchanka/97f8e61ab1c604bb1caafc4247e7595e to your computer and use it in GitHub Desktop.
Detect type of the payment card
export default (cardNumber) => {
// MasterCard
if (/^5[1-5]/.test(cardNumber)) {
return 'mastercard';
}
// Visa
if (/^4/.test(cardNumber)) {
return 'visa';
}
// American Express
if (/^3[47]/.test(cardNumber)) {
return 'amex';
}
// Unknown
return 'unknown';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment