Last active
September 15, 2017 08:26
-
-
Save larchanka/97f8e61ab1c604bb1caafc4247e7595e to your computer and use it in GitHub Desktop.
Detect type of the payment card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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