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
Typically, credit card numbers are all numeric and the length of the credit card number is between 12 digits to 19 digits.
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; }
07-22-2019 03:08 PM
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
Typically, credit card numbers are all numeric and the length of the credit card number is between 12 digits to 19 digits.
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; }
07-22-2019 03:08 PM