public static bool IsValidType(CreditCardTypeId id) { if (id <= CreditCardTypeId.Unk) { return(false); } if (id > CreditCardTypeId.DinersClub) { return(false); } return(true); }
public static string GetCardTestNumber(CreditCardTypeId cardType) { // Return a bogus CC number that passes Luhn and format tests for a given CreditCardTypeId // Src: https://www.paypal.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm // Credit: Scott Dorman, http://www.geekswithblogs.net/sdorman // According to PayPal, the valid test numbers that should be used // for testing card transactions are: // Credit Card Type Credit Card Number // American Express 378282246310005 // American Express 371449635398431 // American Express Corporate 378734493671000 // Diners Club 30569309025904 // Diners Club 38520000023237 // Discover 6011111111111117 // Discover 6011000990139424 // MasterCard 5555555555554444 // MasterCard 5105105105105100 // Visa 4111111111111111 // Visa 4012888888881881 switch (cardType) { case CreditCardTypeId.Amex: return("3782 822463 10005"); case CreditCardTypeId.Discover: return("6011 1111 1111 1117"); case CreditCardTypeId.MasterCard: return("5105 1051 0510 5100"); case CreditCardTypeId.Visa: return("4111 1111 1111 1111"); case CreditCardTypeId.DinersClub: return("30569309025904"); default: return(null); } }
public static bool IsValidNumber(string cardNum) { // Determine the card type based on the number cardNum = GetClean(cardNum); CreditCardTypeId cardType = GetCardTypeFromNumber2(cardNum); if (!IsValidType(cardType)) { return(false); } if (!IsValidLength(cardNum.Length, cardType)) { return(false); } // all cards use Luhn's alg return(IsValidLuhn2(cardNum)); }
public static CreditCardTypeId GetCardTypeFromNumber2(string cardNum) { // Compare the supplied card number with the regex pattern and get reference regex named groups // NOTE: this does not mean the card is valid format/length, just that it resembles a type. // Assume clean cardNum. GroupCollection gc = _cardRegex1.Value.Match(cardNum).Groups; for (CreditCardTypeId id = CreditCardTypeId.Visa; id <= CreditCardTypeId.DinersClub; id++) { // Compare each card type to the named groups to determine which card type the number matches if (gc[id.ToString()].Success) { return(id); } } // Card type is not supported by our system, return null return(CreditCardTypeId.Unk); }
public static bool IsValidNumber2(string cardNum, CreditCardTypeId cardType) { // Assume clean cardNum. if (!IsValidType(cardType)) { return(false); } if (!IsValidLength(cardNum.Length, cardType)) { return(false); } // Make sure the supplied number matches the supplied card type if (!_cardRegex1.Value.Match(cardNum).Groups[cardType.ToString()].Success) { return(false); // The card number does not match the card type } // all cards use Luhn's alg return(IsValidLuhn2(cardNum)); }
public static bool IsValidNumber(string cardNum, CreditCardTypeId cardType) { return(IsValidNumber2(GetClean(cardNum), cardType)); }
public static bool IsValidLength(int len, CreditCardTypeId cardType) { return(true); }