List of utility methods to do Credit Card Check
boolean | IsAmericanExpressCreditCard( String UnformattedAccountNumber) Is American Express Credit Card Pattern p = Pattern.compile("^3[47][0-9]{13}$"); Matcher m = p.matcher(UnformattedAccountNumber); return m.matches(); |
boolean | IsDinersClubCreditCard( String UnformattedAccountNumber) Is Diners Club Credit Card Pattern p = Pattern.compile("^3(?:0[0-5]|[68][0-9])[0-9]{11}$"); Matcher m = p.matcher(UnformattedAccountNumber); return m.matches(); |
boolean | IsDiscoverCreditCard( String UnformattedAccountNumber) Is Discover Credit Card Pattern p = Pattern.compile("^6(?:011|5[0-9]{2})[0-9]{12}$"); Matcher m = p.matcher(UnformattedAccountNumber); return m.matches(); |
boolean | IsJCBCreditCard(String UnformattedAccountNumber) Is JCB Credit Card Pattern p = Pattern.compile("^(?:2131|1800|35\\d{3})\\d{11}$"); Matcher m = p.matcher(UnformattedAccountNumber); return m.matches(); |
boolean | IsMasterCardCreditCard( String UnformattedAccountNumber) Is Master Card Credit Card Pattern p = Pattern.compile("^5[1-5][0-9]{14}$"); Matcher m = p.matcher(UnformattedAccountNumber); return m.matches(); |
boolean | IsVISACreditCard(String UnformattedAccountNumber) Is VISA Credit Card Pattern p = Pattern.compile("^4[0-9]{12}(?:[0-9]{3})?$"); Matcher m = p.matcher(UnformattedAccountNumber); return m.matches(); |
int | FindCreditCard(String AccountNumber) Find Credit Card if (AccountNumber == null) { return NOT_RECOGNIZED; AccountNumber = UnFormatAccountNumber(AccountNumber); AccountNumber = AccountNumber.trim(); if (AccountNumber.length() == 0) { return NOT_RECOGNIZED; if (IsVISACreditCard(AccountNumber)) { return VISA; } else if (IsMasterCardCreditCard(AccountNumber)) { return MASTERCARD; } else if (IsAmericanExpressCreditCard(AccountNumber)) { return AMERICAN_EXPRESS; } else if (IsDinersClubCreditCard(AccountNumber)) { return DINERS_CLUB; } else if (IsDiscoverCreditCard(AccountNumber)) { return DISCOVER; } else if (IsJCBCreditCard(AccountNumber)) { return JCB; } else { return NOT_RECOGNIZED; |
String | FormatAccountNumber( String UnformattedAccountNumber, int subGroupLength, String Seperator) Format Account Number if (UnformattedAccountNumber == null) { return ""; UnformattedAccountNumber = UnFormatAccountNumber(UnformattedAccountNumber); UnformattedAccountNumber = UnformattedAccountNumber.trim(); if (UnformattedAccountNumber.length() == 0) { return ""; if (Seperator == null) { Seperator = DEFAULT_SEPERATOR; if (subGroupLength < 1) { subGroupLength = 4; int end = 0; StringBuilder result = new StringBuilder(); for (int start = 0; start < UnformattedAccountNumber.length(); start += subGroupLength) { end = start + subGroupLength; if (end > UnformattedAccountNumber.length()) { end = UnformattedAccountNumber.length(); result.append(UnformattedAccountNumber.substring(start, end)); result.append(Seperator); String formattedAccountNumber = result.toString(); formattedAccountNumber = formattedAccountNumber.substring(0, formattedAccountNumber.length() - Seperator.length()); return formattedAccountNumber; |
String | FormatAmericanExpress( String UnformattedAccountNumber, String Seperator) Format American Express if (UnformattedAccountNumber == null) { return ""; UnformattedAccountNumber = UnFormatAccountNumber(UnformattedAccountNumber); UnformattedAccountNumber = UnformattedAccountNumber.trim(); if (UnformattedAccountNumber.length() == 0) { return ""; if (Seperator == null) { Seperator = DEFAULT_SEPERATOR; String formattedAccountNumber = ""; StringBuilder sb = new StringBuilder(); if (UnformattedAccountNumber.length() == 15) { sb.append(UnformattedAccountNumber.substring(0, 4)); sb.append(Seperator); sb.append(UnformattedAccountNumber.substring(4, 10)); sb.append(Seperator); sb.append(UnformattedAccountNumber.substring(10, 15)); formattedAccountNumber = sb.toString(); } else { formattedAccountNumber = FormatAccountNumber( UnformattedAccountNumber, 4, Seperator); return formattedAccountNumber; |
String | FormatDinersClub(String UnformattedAccountNumber, String Seperator) Format Diners Club if (UnformattedAccountNumber == null) { return ""; UnformattedAccountNumber = UnFormatAccountNumber(UnformattedAccountNumber); UnformattedAccountNumber = UnformattedAccountNumber.trim(); if (UnformattedAccountNumber.length() == 0) { return ""; if (Seperator == null) { Seperator = DEFAULT_SEPERATOR; String formattedAccountNumber = ""; StringBuilder sb = new StringBuilder(); if (UnformattedAccountNumber.length() == 14) { sb.append(UnformattedAccountNumber.substring(0, 4)); sb.append(Seperator); sb.append(UnformattedAccountNumber.substring(4, 10)); sb.append(Seperator); sb.append(UnformattedAccountNumber.substring(10, 14)); formattedAccountNumber = sb.toString(); } else { formattedAccountNumber = FormatAccountNumber( UnformattedAccountNumber, 4, Seperator); return formattedAccountNumber; |