@Test public void testInvalidCreditCard() { String tituloEleitor = "4369811367191812"; assertFalse(service.validate(tituloEleitor)); }
@Override public boolean validate(String cc) { cc = NON_DIGIT.matcher(cc).replaceAll(""); if (isRepeated(cc)) { return false; } int sum = 0; boolean odd = false; for (int index = cc.length() - 1; index >= 0; index--) { int n = Integer.parseInt(cc.substring(index, index + 1)); if (odd) { n *= 2; if (n > 9) { n = (n % 10) + 1; } } sum += n; odd = !odd; } return (sum % 10 == 0); }
CreditCardRegexValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String cc) { cc = NON_DIGIT.matcher(cc).replaceAll(""); if (isRepeated(cc)) { return false; } int sum = 0; boolean odd = false; for (int index = cc.length() - 1; index >= 0; index--) { int n = Integer.parseInt(cc.substring(index, index + 1)); if (odd) { n *= 2; if (n > 9) { n = (n % 10) + 1; } } sum += n; odd = !odd; } return (sum % 10 == 0); } }
CreditCardRegexValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String cc) { cc = NON_DIGIT.matcher(cc).replaceAll(""); if (isRepeated(cc)) { return false; } int sum = 0; boolean odd = false; for (int index = cc.length() - 1; index >= 0; index--) { int n = Integer.parseInt(cc.substring(index, index + 1)); if (odd) { n *= 2; if (n > 9) { n = (n % 10) + 1; } } sum += n; odd = !odd; } return (sum % 10 == 0); }  }
CreditCardRegexValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String cc) { cc = NON_DIGIT.matcher(cc).replaceAll(""); if (isRepeated(cc)) { return false; } int sum = 0; boolean odd = false; for (int index = cc.length() - 1; index >= 0; index--) { int n = Integer.parseInt(cc.substring(index, index + 1)); if (odd) { n *= 2; if (n > 9) { n = (n % 10) + 1; } } sum += n; odd = !odd; } return (sum % 10 == 0); }  @Override void init(File confDir); @Override boolean validate(String cc); @Override String format(String hit); @Override List<String> getRegexNames(); }
CreditCardRegexValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String cc) { cc = NON_DIGIT.matcher(cc).replaceAll(""); if (isRepeated(cc)) { return false; } int sum = 0; boolean odd = false; for (int index = cc.length() - 1; index >= 0; index--) { int n = Integer.parseInt(cc.substring(index, index + 1)); if (odd) { n *= 2; if (n > 9) { n = (n % 10) + 1; } } sum += n; odd = !odd; } return (sum % 10 == 0); }  @Override void init(File confDir); @Override boolean validate(String cc); @Override String format(String hit); @Override List<String> getRegexNames();  }