Last active
January 2, 2016 14:59
-
-
Save jmarmolejos/8320190 to your computer and use it in GitHub Desktop.
Quick port of the function used here to detect the credit card type: http://webstandardssherpa.com/reviews/auto-detecting-credit-card-type
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
// Quick port of the function used here to detect the credit card type: | |
// http://webstandardssherpa.com/reviews/auto-detecting-credit-card-type | |
public static string GetCardType(string Number) | |
{ | |
//start without knowing the credit card type | |
var result = "unknown"; | |
//first check for MasterCard | |
if (Regex.Match(Number, @"^5[1-5]").Success) | |
{ | |
result = "mastercard"; | |
} | |
//then check for Visa | |
else if (Regex.Match(Number, @"^4").Success) | |
{ | |
result = "visa"; | |
} | |
//then check for AmEx | |
else if (Regex.Match(Number, @"^3[47]").Success) | |
{ | |
result = "amex"; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment