public static String validateCreditCardNumber(String creditCardNumber){
  if (creditCardNumber == null || creditCardNumber.length() == 0)   return "CreditCardNumberError";
  String ccNumber1=checkNumeric(creditCardNumber);
  int ccLength=ccNumber1.length();
  StringBuffer buf=new StringBuffer();
  for (int i=ccLength; i != 0; i--)   buf.append(ccNumber1.charAt(i - 1));
  String ccNumber=buf.toString();
  int sum=0;
  for (int i=0; i < ccLength; i++) {
    int digit=Character.getNumericValue(ccNumber.charAt(i));
    if (i % 2 == 1) {
      digit*=2;
      if (digit > 9)       digit-=9;
    }
    sum+=digit;
  }
  if (sum % 10 == 0)   return "";
  s_log.fine("validateCreditCardNumber - " + creditCardNumber + " -> "+ ccNumber+ ", Luhn="+ sum);
  return "CreditCardNumberError";
}

public static String validateCreditCardNumber ( String creditCardNumber ) { if ( creditCardNumber == null || creditCardNumber . length ( ) == 0 ) return "CreditCardNumberError" ; String ccNumber1 = checkNumeric ( creditCardNumber ) ; int ccLength = ccNumber1 . length ( ) ; StringBuffer buf = new StringBuffer ( ) ; for ( int i = ccLength ; i != 0 ; i -- ) buf . append ( ccNumber1 . charAt ( i - 1 ) ) ; String ccNumber = buf . toString ( ) ; int sum = 0 ; for ( int i = 0 ; i < ccLength ; i ++ ) { int digit = Character . getNumericValue ( ccNumber . charAt ( i ) ) ; if ( i % 2 == 1 ) { digit *= 2 ; if ( digit > 9 ) digit -= 9 ; } sum += digit ; } if ( sum % 10 == 0 ) return "" ; s_log . fine ( "validateCreditCardNumber - " + creditCardNumber + " -> " + ccNumber + ", Luhn=" + sum ) ; return "CreditCardNumberError" ; }
validate credit card number . - based on luhn formula
