MCPcopy Create free account
hub / github.com/banq/jdonframework / isCreditCard

Method isCreditCard

src/main/java/com/jdon/util/UtilValidate.java:857–899  ·  view source on GitHub ↗

Checks credit card number with Luhn Mod-10 test @param stPassed a string representing a credit card number @return true, if the credit card number passes the Luhn Mod-10 test, false otherwise

(String stPassed)

Source from the content-addressed store, hash-verified

855 * @return true, if the credit card number passes the Luhn Mod-10 test, false otherwise
856 */
857 public static boolean isCreditCard(String stPassed) {
858 if (isEmpty(stPassed)) return defaultEmptyOK;
859 String st = stripCharsInBag(stPassed, creditCardDelimiters);
860
861 int sum = 0;
862 int mul = 1;
863 int l = st.length();
864
865 // Encoding only works on cards with less than 19 digits
866 if (l > 19) return (false);
867 for (int i = 0; i < l; i++) {
868 String digit = st.substring(l - i - 1, l - i);
869 int tproduct = 0;
870
871 try {
872 tproduct = Integer.parseInt(digit, 10) * mul;
873 } catch (Exception e) {
874 Debug.logWarning(e.getMessage());
875 return false;
876 }
877 if (tproduct >= 10)
878 sum += (tproduct % 10) + 1;
879 else
880 sum += tproduct;
881 if (mul == 1)
882 mul++;
883 else
884 mul--;
885 }
886 // Uncomment the following line to help create credit card numbers
887 // 1. Create a dummy number with a 0 as the last digit
888 // 2. Examine the sum written out
889 // 3. Replace the last digit with the difference between the sum and
890 // the next multiple of 10.
891
892 // document.writeln("<BR>Sum = ",sum,"<BR>");
893 // alert("Sum = " + sum);
894
895 if ((sum % 10) == 0)
896 return true;
897 else
898 return false;
899 }
900
901 /** Checks to see if the cc number is a valid Visa number
902 *

Callers 9

isVisaMethod · 0.95
isMasterCardMethod · 0.95
isAmericanExpressMethod · 0.95
isDinersClubMethod · 0.95
isDiscoverMethod · 0.95
isEnRouteMethod · 0.95
isJCBMethod · 0.95
isAnyCardMethod · 0.95
getCardTypeMethod · 0.95

Calls 3

isEmptyMethod · 0.95
stripCharsInBagMethod · 0.95
logWarningMethod · 0.95

Tested by

no test coverage detected