- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I am using the C# integration to do the payment, i want to know the minimum lenght of all credit card types to validate in my BLL method.
Solved! Go to Solution.
โ07-22-2019 03:38 AM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Typically, credit card numbers are all numeric and the length of the credit card number is between 12 digits to 19 digits.
- 14, 15, 16 digits โ Diners Club
- 15 digits โ American Express
- 13, 16 digits โ Visa
- 16 digits - MasterCard
For C#, the following validates a credit card number using the Luhn (Mod 10 algorithm):
public static bool Mod10Check(string creditCardNumber) { if (string.IsNullOrEmpty(creditCardNumber)) { return false; } int sumOfDigits = creditCardNumber.Where((e) => e >= '0' && e <= '9') .Reverse() .Select((e, i) => ((int)e - 48) * (i % 2 == 0 ? 1 : 2)) .Sum((e) => e / 10 + e % 10); return sumOfDigits % 10 == 0; }
Certified Authorize.net developers

โ07-22-2019 03:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There have been cards issued that are only 12 characters. Most cards are 16 digits. The standard way of validating is to use the Luhn algorithm. There's a lot of free sample code out there with it that you can incorporate.
โ07-22-2019 02:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Typically, credit card numbers are all numeric and the length of the credit card number is between 12 digits to 19 digits.
- 14, 15, 16 digits โ Diners Club
- 15 digits โ American Express
- 13, 16 digits โ Visa
- 16 digits - MasterCard
For C#, the following validates a credit card number using the Luhn (Mod 10 algorithm):
public static bool Mod10Check(string creditCardNumber) { if (string.IsNullOrEmpty(creditCardNumber)) { return false; } int sumOfDigits = creditCardNumber.Where((e) => e >= '0' && e <= '9') .Reverse() .Select((e, i) => ((int)e - 48) * (i % 2 == 0 ? 1 : 2)) .Sum((e) => e / 10 + e % 10); return sumOfDigits % 10 == 0; }
Certified Authorize.net developers

โ07-22-2019 03:08 PM

