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; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.