@Test public void testValidCNH() { String cnh = "08355950810"; assertTrue(service.validate(cnh)); }
@Override public boolean validate(String cnh) { cnh = NON_DIGIT.matcher(cnh).replaceAll(""); if (isRepeated(cnh.substring(0, cnh.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; int incDigit2 = 0; for (int index = 0, weight = 9, digit; index < 9; index++, weight--) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; incDigit2 = 2; } else digit1 = sum; sum = 0; for (int index = 0, weight = 1, digit; index < 9; index++, weight++) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) digit2 = 0; else digit2 = sum - incDigit2; return cnh.equals(cnh.substring(0, 9) + digit1 + digit2); }
CNHValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String cnh) { cnh = NON_DIGIT.matcher(cnh).replaceAll(""); if (isRepeated(cnh.substring(0, cnh.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; int incDigit2 = 0; for (int index = 0, weight = 9, digit; index < 9; index++, weight--) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; incDigit2 = 2; } else digit1 = sum; sum = 0; for (int index = 0, weight = 1, digit; index < 9; index++, weight++) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) digit2 = 0; else digit2 = sum - incDigit2; return cnh.equals(cnh.substring(0, 9) + digit1 + digit2); } }
CNHValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String cnh) { cnh = NON_DIGIT.matcher(cnh).replaceAll(""); if (isRepeated(cnh.substring(0, cnh.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; int incDigit2 = 0; for (int index = 0, weight = 9, digit; index < 9; index++, weight--) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; incDigit2 = 2; } else digit1 = sum; sum = 0; for (int index = 0, weight = 1, digit; index < 9; index++, weight++) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) digit2 = 0; else digit2 = sum - incDigit2; return cnh.equals(cnh.substring(0, 9) + digit1 + digit2); }  }
CNHValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String cnh) { cnh = NON_DIGIT.matcher(cnh).replaceAll(""); if (isRepeated(cnh.substring(0, cnh.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; int incDigit2 = 0; for (int index = 0, weight = 9, digit; index < 9; index++, weight--) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; incDigit2 = 2; } else digit1 = sum; sum = 0; for (int index = 0, weight = 1, digit; index < 9; index++, weight++) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) digit2 = 0; else digit2 = sum - incDigit2; return cnh.equals(cnh.substring(0, 9) + digit1 + digit2); }  @Override void init(File confDir); @Override boolean validate(String cnh); @Override String format(String hit); @Override List<String> getRegexNames(); }
CNHValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String cnh) { cnh = NON_DIGIT.matcher(cnh).replaceAll(""); if (isRepeated(cnh.substring(0, cnh.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; int incDigit2 = 0; for (int index = 0, weight = 9, digit; index < 9; index++, weight--) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; incDigit2 = 2; } else digit1 = sum; sum = 0; for (int index = 0, weight = 1, digit; index < 9; index++, weight++) { digit = Integer.parseInt(cnh.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) digit2 = 0; else digit2 = sum - incDigit2; return cnh.equals(cnh.substring(0, 9) + digit1 + digit2); }  @Override void init(File confDir); @Override boolean validate(String cnh); @Override String format(String hit); @Override List<String> getRegexNames();  }