Regex Get Credit Card Type - Javascript

Regex Get Credit Card Type - Javascript

code snippet

javascript
function getCreditCardType(accountNumber) {
    var result = "";
    if (/^5[1-5]/.test(accountNumber)) { result = "mastercard"; }
    else if (/^4/.test(accountNumber)) { result = "visa"; }
    else if (/^3[47]/.test(accountNumber)) { result = "amex"; }
    else if (/^3(?:0[0-5]|[68][0-9])/.test(accountNumber)) { result = "dinner"; }
    return result;
}

"The best preparation for tomorrow is doing your best today"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.