Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for /trunk/CCCheckerPro/src/com/gnuc/java/ccc/Luhn.java #1

Open
GoogleCodeExporter opened this issue Aug 9, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

//---------------------------------------------------------
// Checks for valid credit card number using Luhn algorithm
//---------------------------------------------------------

public abstract class LuhnCheck {

  //--------------------------------
  // Filter out non-digit characters
  //--------------------------------

  private static String getDigitsOnly (String s) {
    StringBuffer digitsOnly = new StringBuffer ();
    char c;
    for (int i = 0; i < s.length (); i++) {
      c = s.charAt (i);
      if (Character.isDigit (c)) {
        digitsOnly.append (c);
      }
    }
    return digitsOnly.toString ();
  }

  //-------------------
  // Perform Luhn check
  //-------------------

  public static boolean isValid (String cardNumber) {
    String digitsOnly = getDigitsOnly (cardNumber);
    int sum = 0;
    int digit = 0;
    int addend = 0;
    boolean timesTwo = false;

    for (int i = digitsOnly.leng

Original issue reported on code.google.com by [email protected] on 14 Jun 2012 at 11:02

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant