Class CreditCardValidator


  • public class CreditCardValidator
    extends java.lang.Object
    Class to validate credit card PAN numbers. PAN numbers are formed by IIN (Issuer Identification Number) followed by a series of digits + the check digit (using Luhn algorithm), if available for a given credit card network. Notice that the first digit of the IIN corresponds to a MII (Major Industry Identifier). This class also provides functionality to detect network of a given credit card PAN number. Notice that network detection and validation is not 100% accurate, hence it is suggested to never prevent users from completing payments if validation does not pass or network cannot be detected. In those cases simply a warning can be shown to the user indicating that payment data might be wrong. Notice as well that if network is detected and validation passes, then it is almost certain that payment data is correct.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte[][] AMEX_GROUPING
      Constant defining digit groups for American Express.
      protected static boolean AMEX_HAS_VALIDATION
      Constant indicating whether American Express uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] AMEX_IIN
      Constant containing IIN ranges reserved for American Express.
      protected static boolean AMEX_IS_ACTIVE
      Constant indicating whether American Express network is still being used.
      private static byte[][] AMEX_LENGTH
      Constant containing valid lengths for American Express.
      protected static boolean BANKCARD_HAS_VALIDATION
      Constant indicating whether Bankcard uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] BANKCARD_IIN
      Constant containing IIN ranges reserved for Bankcard.
      protected static boolean BANKCARD_IS_ACTIVE
      Constant indicating whether Bankcard network is still being used.
      private static byte[][] BANKCARD_LENGTH
      Constant containing valid lengths for Bankcard.
      protected static boolean CHINA_UNIONPAY_HAS_VALIDATION
      Constant indicating whether China UnionPay uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] CHINA_UNIONPAY_IIN
      Constant containing IIN ranges reserved for China UnionPay.
      protected static boolean CHINA_UNIONPAY_IS_ACTIVE
      Constant indicating whether China UnionPay network is still being used.
      private static byte[][] CHINA_UNIONPAY_LENGTH
      Constant containing valid lengths for China UnionPay.
      private static byte[][] DEFAULT_GROUPING
      Constant defining digit groups for any other network or unknown networks.
      protected static boolean DINERS_CLUB_CARTE_BLANCHE_HAS_VALIDATION
      Constant indicating whether Diners Club Carte Blanche uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] DINERS_CLUB_CARTE_BLANCHE_IIN
      Constant containing IIN ranges reserved for Diners Club Carte Blanche.
      protected static boolean DINERS_CLUB_CARTE_BLANCHE_IS_ACTIVE
      Constant indicating whether Diners Club Carte Blanche network is still being used.
      private static byte[][] DINERS_CLUB_CARTE_BLANCHE_LENGTH
      Constant containing valid lengths for Diners Club Carte Blanche.
      private static byte[][] DINERS_CLUB_ENROUTE_GROUPING
      Constant defining digit groups for Dinners club enroute.
      protected static boolean DINERS_CLUB_ENROUTE_HAS_VALIDATION
      Constant indicating whether Diners Club enRoute uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] DINERS_CLUB_ENROUTE_IIN
      Constant containing IIN ranges reserved for Diners Club enRoute.
      protected static boolean DINERS_CLUB_ENROUTE_IS_ACTIVE
      Constant indicating whether Diners Club enRoute network is still being used.
      private static byte[][] DINERS_CLUB_ENROUTE_LENGTH
      Constant containing valid lengths for Diners Club enRoute.
      private static byte[][] DINERS_CLUB_INTERATIONAL_GROUPING
      Constant defining digit groups for Dinners club internacional.
      protected static boolean DINERS_CLUB_INTERATIONAL_HAS_VALIDATION
      Constant indicating whether Diners Club International uses Luhn validation to ensure that PAN is valid.
      protected static boolean DINERS_CLUB_INTERATIONAL_IS_ACTIVE
      Constant indicating whether Diners Club International network is still being used.
      private static java.lang.String[][] DINERS_CLUB_INTERNATIONAL_IIN
      Constant containing IIN ranges reserved for Diners Club International.
      private static byte[][] DINERS_CLUB_INTERNATIONAL_LENGTH
      Constant containing valid lengths for Diners Club International.
      protected static boolean DINERS_CLUB_USA_CA_HAS_VALIDATION
      Constant indicating whether Diners Club USA and Canada uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] DINERS_CLUB_USA_CA_IIN
      Constant containing IIN ranges reserved for Diners Club USA and Canada.
      protected static boolean DINERS_CLUB_USA_CA_IS_ACTIVE
      Constant indicating whether Diners Club USA and Canada network is still being used.
      private static byte[][] DINERS_CLUB_USA_CA_LENGTH
      Constant containing valid lengths for Diners Club USA and Canada.
      private static byte[][] DISCOVER_GROUPING
      Constant defining digit groups for Discover.
      protected static boolean DISCOVER_HAS_VALIDATION
      Constant indicating whether Discover uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] DISCOVER_IIN
      Constant containing IIN ranges reserved for Discover.
      protected static boolean DISCOVER_IS_ACTIVE
      Constant indicating whether Discover network is still being used.
      private static byte[][] DISCOVER_LENGTH
      Constant containing valid lengths for Discover.
      protected static boolean INSTAPAYMENT_HAS_VALIDATION
      Constant indicating whether InstaPayment uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] INSTAPAYMENT_IIN
      Constant containing IIN ranges reserved for InstaPayment.
      protected static boolean INSTAPAYMENT_IS_ACTIVE
      Constant indicating whether InstaPayment network is still being used.
      private static byte[][] INSTAPAYMENT_LENGTH
      Constant containing valid lengths for InstaPayment.
      protected static boolean JCB_HAS_VALIDATION
      Constant indicating whether JCB uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] JCB_IIN
      Constant containing IIN ranges reserved for JCB.
      protected static boolean JCB_IS_ACTIVE
      Constant indicating whether JCB network is still being used.
      private static byte[][] JCB_LENGTH
      Constant containing valid lengths for JCB.
      protected static boolean LASER_HAS_VALIDATION
      Constant indicating whether Laser uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] LASER_IIN
      Constant containing IIN ranges reserved for Laser.
      protected static boolean LASER_IS_ACTIVE
      Constant indicating whether Laser network is still being used.
      private static byte[][] LASER_LENGTH
      Constant containing valid lengths for Laser.
      protected static boolean MAESTRO_HAS_VALIDATION
      Constant indicating whether Maestro uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] MAESTRO_IIN
      Constant containing IIN ranges reserved for Maestro.
      protected static boolean MAESTRO_IS_ACTIVE
      Constant indicating whether Maestro network is still being used.
      private static byte[][] MAESTRO_LENGTH
      Constant containing valid lengths for Maestro.
      private static byte[][] MASTERCARD_GROUPING
      Constant defining digit groups for Mastercard.
      protected static boolean MASTERCARD_HAS_VALIDATION
      Constant indicating whether MasterCard uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] MASTERCARD_IIN
      Constant containing IIN ranges reserved for MasterCard.
      protected static boolean MASTERCARD_IS_ACTIVE
      Constant indicating whether MasterCard network is still being used.
      private static byte[][] MASTERCARD_LENGTH
      Constant containing valid lengths for MasterCard.
      static int MAX_LENGTH
      Maximum allowed length for a credit card PAN.
      static int MIN_LENGTH
      Minimum allowed length for a credit card PAN.
      protected static boolean SOLO_HAS_VALIDATION
      Constant indicating whether Solo uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] SOLO_IIN
      Constant containing IIN ranges reserved for Solo.
      protected static boolean SOLO_IS_ACTIVE
      Constant indicating whether Solo network is still being used.
      private static byte[][] SOLO_LENGTH
      Constant containing valid lengths for Solo.
      protected static boolean SWITCH_HAS_VALIDATION
      Constant indicating whether Switch uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] SWITCH_IIN
      Constant containing IIN ranges reserved for Switch.
      protected static boolean SWITCH_IS_ACTIVE
      Constant indicating whether Switch network is still being used.
      private static byte[][] SWITCH_LENGTH
      Constant containing valid lengths for Switch.
      private static byte[][] VISA_ELECTRON_GROUPING
      Constant defining digit groups for VISA Electron.
      protected static boolean VISA_ELECTRON_HAS_VALIDATION
      Constant indicating whether VISA Electron uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] VISA_ELECTRON_IIN
      Constant containing IIN ranges reserved for VISA Electron.
      protected static boolean VISA_ELECTRON_IS_ACTIVE
      Constant indicating whether VISA Electron network is still being used.
      private static byte[][] VISA_ELECTRON_LENGTH
      Constant containing valid lengths for VISA Electron.
      private static byte[][] VISA_GROUPING
      Constant defining digit groups for VISA.
      protected static boolean VISA_HAS_VALIDATION
      Constant indicating whether VISA uses Luhn validation to ensure that PAN is valid.
      private static java.lang.String[][] VISA_IIN
      Constant containing IIN ranges reserved for VISA.
      protected static boolean VISA_IS_ACTIVE
      Constant indicating whether VISA network is still being used.
      private static byte[][] VISA_LENGTH
      Constant containing valid lengths for VISA.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CreditCardValidator()
      Constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static byte computeCheck​(byte[] digitsWithoutCheck)
      Computes checksum using Luhn algorithm.
      protected static CreditCardNetwork detectNetworkFromPAN​(byte[] panDigits)
      Detects credit card network by using provided credit card PAN digits.
      static CreditCardNetwork detectNetworkFromPAN​(java.lang.String pan)
      Detects credit card network by using provided credit card PAN value.
      static int getMaxDigitsForGroupAndNetwork​(int groupPos, CreditCardNetwork network)
      Returns maximum number of allowed digits for provided group position (starting at zero until the maximum number of groups minus one).
      static int getMinDigitsForGroupAndNetwork​(int groupPos, CreditCardNetwork network)
      Returns minimum number of required digits for provided group position (starting at zero until the maximum number of groups minus one).
      static int getNumberOfGroupsForNetwork​(CreditCardNetwork network)
      Returns number of digit groups for provided credit card network.
      protected static byte[][] groupingsForNetwork​(CreditCardNetwork network)
      Returns credit card digit groupings for provided credit card network.
      protected static boolean isAmericanExpressIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to American Express IIN (Issuer Identification Number).
      static boolean isAmericanExpressIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to American Express IIN (Issuer Identification Number).
      protected static boolean isAmericanExpressValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for American Express cards.
      static boolean isAmericanExpressValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for American Express cards.
      protected static boolean isBankcardIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to BankCard IIN (Issuer Identification Number).
      static boolean isBankcardIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to BankCard IIN (Issuer Identification Number).
      protected static boolean isBankcardValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for BankCard cards.
      static boolean isBankcardValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for BankCard cards.
      protected static boolean isChinaUnionPayIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to China UnionPay IIN (Issuer Identification Number).
      static boolean isChinaUnionPayIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to China UnionPay IIN (Issuer Identification Number).
      protected static boolean isChinaUnionPayValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for China UnionPay cards.
      static boolean isChinaUnionPayValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for China UnionPay cards.
      protected static boolean isDinersClubCarteBlancheIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits corresponds to Diners Club Carte Blanche IIN (Issuer Identification Number).
      static boolean isDinersClubCarteBlancheIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Diners Club Carte Blanche IIN (Issuer Identification Number).
      protected static boolean isDinersClubCarteBlancheValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Diners Club Carte Blanche cards.
      static boolean isDinersClubCarteBlancheValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Diners Club Carte Blanche cards.
      protected static boolean isDinersClubEnrouteIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits corresponds to Diners Club Enroute IIN (Issuer Identification Number).
      static boolean isDinersClubEnrouteIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Diners Club Enroute IIN (Issuer Identification Number).
      protected static boolean isDinersClubEnrouteValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Diners Club Enroute cards.
      static boolean isDinersClubEnrouteValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Diners Club Enroute cards.
      protected static boolean isDinersClubInternationalIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits corresponds to Diners Club International IIN (Issuer Identification Number).
      static boolean isDinersClubInternationalIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Diners Club International IIN (Issuer Identification Number).
      protected static boolean isDinersClubInternationalValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Diners Club International cards.
      static boolean isDinersClubInternationalValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Diners Club International cards.
      protected static boolean isDinersClubUSACanadaIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits corresponds to Diners Club USA and Canada IIN (Issuer Identification Number).
      static boolean isDinersClubUSACanadaIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Diners Club USA and Canada IIN (Issuer Identification Number).
      protected static boolean isDinersClubUSACanadaValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Diners Club USA and Canada cards.
      static boolean isDinersClubUSACanadaValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Diners Club USA and Canada cards.
      protected static boolean isDiscoverIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits corresponds to Discover IIN (Issuer Identification Number).
      static boolean isDiscoverIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Discover IIN (Issuer Identification Number).
      protected static boolean isDiscoverValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Discover cards.
      static boolean isDiscoverValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Discover cards.
      protected static boolean isInstaPaymentIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits corresponds to InstaPayment IIN (Issuer Identification Number).
      static boolean isInstaPaymentIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to InstaPayment IIN (Issuer Identification Number).
      protected static boolean isInstaPaymentValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for InstaPayment cards.
      static boolean isInstaPaymentValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for InstaPayment cards.
      protected static boolean isJCBIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to JCB IIN (Issuer Identification Number).
      static boolean isJCBIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to JCB IIN (Issuer Identification Number).
      protected static boolean isJCBValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for JCB cards.
      static boolean isJCBValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for JCB cards.
      protected static boolean isLaserIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to Laser IIN (Issuer Identification Number).
      static boolean isLaserIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Laser IIN (Issuer Identification Number).
      protected static boolean isLaserValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Laser cards.
      static boolean isLaserValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Laser cards.
      protected static boolean isMaestroIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to Maestro IIN (Issuer Identification Number).
      static boolean isMaestroIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Maestro IIN (Issuer Identification Number).
      protected static boolean isMaestroValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Maestro cards.
      static boolean isMaestroValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Maestro cards.
      protected static boolean isMastercardIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to Mastercard IIN (Issuer Identification Number).
      static boolean isMastercardIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Mastercard IIN (Issuer Identification Number).
      protected static boolean isMastercardValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Mastercard cards.
      static boolean isMastercardValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Mastercard cards.
      static boolean isNetworkActive​(CreditCardNetwork network)
      Indicates if provided credit card network is still being used commercially.
      protected static boolean isSoloIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to Solo IIN (Issuer Identification Number).
      static boolean isSoloIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Solo IIN (Issuer Identification Number).
      protected static boolean isSoloValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Solo cards.
      static boolean isSoloValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Solo cards.
      protected static boolean isSwitchIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to Switch IIN (Issuer Identification Number).
      static boolean isSwitchIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to Switch IIN (Issuer Identification Number).
      protected static boolean isSwitchValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for Switch cards.
      static boolean isSwitchValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for Switch cards.
      protected static boolean isValid​(byte[] panDigits)
      Indicates if provided credit card PAN is valid by detecting its assigned credit card network, checking its length and validating its checksum if network supports validation.
      static boolean isValid​(java.lang.String pan)
      Indicates if provided credit card PAN is valid by detecting its assigned credit card network, checking its length and validating its checksum if network supports validation.
      static boolean isValidationEnabledForNetwork​(CreditCardNetwork network)
      Indicates if a given credit card network uses Luhn algorithm to validate PAN values.
      protected static boolean isValidChecksumForPAN​(byte[] panDigits)
      Validates provided credit card PAN using Luhn algorithm assuming that the last digit of provided PAN corresponds to its checksum value.
      static boolean isValidChecksumForPAN​(java.lang.String pan)
      Validates provided credit card PAN using Luhn algorithm assuming that the last digit of provided PAN corresponds to its checksum value.
      protected static boolean isValidIIN​(byte[] panDigits, java.lang.String[][] iins)
      Internal method to check whether provided array of PAN digits corresponds to a valid IIN by checking the array of valid IIN ranges.
      protected static boolean isValidIIN​(java.lang.String pan, java.lang.String[][] iins)
      Internal method to check whether provided credit card PAN corresponds to a valid IIN by checking the array of valid IIN ranges.
      protected static boolean isValidLength​(byte[] panDigits)
      Detects network for provided PAN digits and indicates if provided array of credit card PAN digits has an appropriate length for provided credit card network.
      protected static boolean isValidLength​(byte[] panDigits, byte[][] lengths)
      Internal method to determine whether length of provided array of credit card PAN digits is valid based on array of valid length ranges.
      protected static boolean isValidLength​(byte[] panDigits, CreditCardNetwork network)
      Indicates if provided array of credit card PAN digits has an appropriate length for provided credit card network.
      static boolean isValidLength​(java.lang.String pan)
      Detects network for provided PAN and indicates if provided credit card PAN has an appropriate length for provided credit card network.
      protected static boolean isValidLength​(java.lang.String pan, byte[][] lengths)
      Internal method to determine whether length of provided credit card PAN is valid based on array of valid length ranges.
      static boolean isValidLength​(java.lang.String pan, CreditCardNetwork network)
      Indicates if provided credit card PAN has an appropriate length for provided credit card network.
      protected static boolean isValidMII​(byte[] panDigits)
      Indicates if provided array of credit card PAN digits corresponds to any valid MII (Major Industry Identifier).
      static boolean isValidMII​(java.lang.String pan)
      Indicates if provided credit card PAN value corresponds to any valid MII (Major Industry Identifier).
      protected static boolean isVISAElectronIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to VISA Electron IIN (Issuer Identification Number).
      static boolean isVISAElectronIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to VISA Electron IIN (Issuer Identification Number).
      protected static boolean isVISAElectronValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for VISA Electron cards.
      static boolean isVISAElectronValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for VISA Electron cards.
      protected static boolean isVISAIIN​(byte[] panDigits)
      Indicates if provided credit card PAN digits correspond to VISA IIN (Issuer Identification Number).
      static boolean isVISAIIN​(java.lang.String pan)
      Indicates if provided credit card PAN corresponds to VISA IIN (Issuer Identification Number).
      protected static boolean isVISAValidLength​(byte[] panDigits)
      Indicates if provided credit card PAN digits have valid length for VISA cards.
      static boolean isVISAValidLength​(java.lang.String pan)
      Indicates if provided credit card PAN has valid length for VISA cards.
      protected static int numLeadingZeros​(java.lang.String iin)
      Computes number of leading zeros on any given IIN.
      static byte[] toDigits​(java.lang.String pan)
      Converts a credit card PAN from its string representation into an array containing PAN digits.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MIN_LENGTH

        public static final int MIN_LENGTH
        Minimum allowed length for a credit card PAN.
        See Also:
        Constant Field Values
      • MAX_LENGTH

        public static final int MAX_LENGTH
        Maximum allowed length for a credit card PAN.
        See Also:
        Constant Field Values
      • AMEX_HAS_VALIDATION

        protected static final boolean AMEX_HAS_VALIDATION
        Constant indicating whether American Express uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • AMEX_IS_ACTIVE

        protected static final boolean AMEX_IS_ACTIVE
        Constant indicating whether American Express network is still being used.
        See Also:
        Constant Field Values
      • BANKCARD_HAS_VALIDATION

        protected static final boolean BANKCARD_HAS_VALIDATION
        Constant indicating whether Bankcard uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • BANKCARD_IS_ACTIVE

        protected static final boolean BANKCARD_IS_ACTIVE
        Constant indicating whether Bankcard network is still being used.
        See Also:
        Constant Field Values
      • CHINA_UNIONPAY_HAS_VALIDATION

        protected static final boolean CHINA_UNIONPAY_HAS_VALIDATION
        Constant indicating whether China UnionPay uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • CHINA_UNIONPAY_IS_ACTIVE

        protected static final boolean CHINA_UNIONPAY_IS_ACTIVE
        Constant indicating whether China UnionPay network is still being used.
        See Also:
        Constant Field Values
      • DINERS_CLUB_CARTE_BLANCHE_HAS_VALIDATION

        protected static final boolean DINERS_CLUB_CARTE_BLANCHE_HAS_VALIDATION
        Constant indicating whether Diners Club Carte Blanche uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • DINERS_CLUB_CARTE_BLANCHE_IS_ACTIVE

        protected static final boolean DINERS_CLUB_CARTE_BLANCHE_IS_ACTIVE
        Constant indicating whether Diners Club Carte Blanche network is still being used.
        See Also:
        Constant Field Values
      • DINERS_CLUB_ENROUTE_HAS_VALIDATION

        protected static final boolean DINERS_CLUB_ENROUTE_HAS_VALIDATION
        Constant indicating whether Diners Club enRoute uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • DINERS_CLUB_ENROUTE_IS_ACTIVE

        protected static final boolean DINERS_CLUB_ENROUTE_IS_ACTIVE
        Constant indicating whether Diners Club enRoute network is still being used.
        See Also:
        Constant Field Values
      • DINERS_CLUB_INTERATIONAL_HAS_VALIDATION

        protected static final boolean DINERS_CLUB_INTERATIONAL_HAS_VALIDATION
        Constant indicating whether Diners Club International uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • DINERS_CLUB_INTERATIONAL_IS_ACTIVE

        protected static final boolean DINERS_CLUB_INTERATIONAL_IS_ACTIVE
        Constant indicating whether Diners Club International network is still being used.
        See Also:
        Constant Field Values
      • DINERS_CLUB_USA_CA_HAS_VALIDATION

        protected static final boolean DINERS_CLUB_USA_CA_HAS_VALIDATION
        Constant indicating whether Diners Club USA and Canada uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • DINERS_CLUB_USA_CA_IS_ACTIVE

        protected static final boolean DINERS_CLUB_USA_CA_IS_ACTIVE
        Constant indicating whether Diners Club USA and Canada network is still being used.
        See Also:
        Constant Field Values
      • DISCOVER_HAS_VALIDATION

        protected static final boolean DISCOVER_HAS_VALIDATION
        Constant indicating whether Discover uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • DISCOVER_IS_ACTIVE

        protected static final boolean DISCOVER_IS_ACTIVE
        Constant indicating whether Discover network is still being used.
        See Also:
        Constant Field Values
      • INSTAPAYMENT_HAS_VALIDATION

        protected static final boolean INSTAPAYMENT_HAS_VALIDATION
        Constant indicating whether InstaPayment uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • INSTAPAYMENT_IS_ACTIVE

        protected static final boolean INSTAPAYMENT_IS_ACTIVE
        Constant indicating whether InstaPayment network is still being used.
        See Also:
        Constant Field Values
      • JCB_HAS_VALIDATION

        protected static final boolean JCB_HAS_VALIDATION
        Constant indicating whether JCB uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • JCB_IS_ACTIVE

        protected static final boolean JCB_IS_ACTIVE
        Constant indicating whether JCB network is still being used.
        See Also:
        Constant Field Values
      • LASER_HAS_VALIDATION

        protected static final boolean LASER_HAS_VALIDATION
        Constant indicating whether Laser uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • LASER_IS_ACTIVE

        protected static final boolean LASER_IS_ACTIVE
        Constant indicating whether Laser network is still being used.
        See Also:
        Constant Field Values
      • MAESTRO_HAS_VALIDATION

        protected static final boolean MAESTRO_HAS_VALIDATION
        Constant indicating whether Maestro uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • MAESTRO_IS_ACTIVE

        protected static final boolean MAESTRO_IS_ACTIVE
        Constant indicating whether Maestro network is still being used.
        See Also:
        Constant Field Values
      • MASTERCARD_HAS_VALIDATION

        protected static final boolean MASTERCARD_HAS_VALIDATION
        Constant indicating whether MasterCard uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • MASTERCARD_IS_ACTIVE

        protected static final boolean MASTERCARD_IS_ACTIVE
        Constant indicating whether MasterCard network is still being used.
        See Also:
        Constant Field Values
      • SOLO_HAS_VALIDATION

        protected static final boolean SOLO_HAS_VALIDATION
        Constant indicating whether Solo uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • SOLO_IS_ACTIVE

        protected static final boolean SOLO_IS_ACTIVE
        Constant indicating whether Solo network is still being used.
        See Also:
        Constant Field Values
      • SWITCH_HAS_VALIDATION

        protected static final boolean SWITCH_HAS_VALIDATION
        Constant indicating whether Switch uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • SWITCH_IS_ACTIVE

        protected static final boolean SWITCH_IS_ACTIVE
        Constant indicating whether Switch network is still being used.
        See Also:
        Constant Field Values
      • VISA_HAS_VALIDATION

        protected static final boolean VISA_HAS_VALIDATION
        Constant indicating whether VISA uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • VISA_IS_ACTIVE

        protected static final boolean VISA_IS_ACTIVE
        Constant indicating whether VISA network is still being used.
        See Also:
        Constant Field Values
      • VISA_ELECTRON_HAS_VALIDATION

        protected static final boolean VISA_ELECTRON_HAS_VALIDATION
        Constant indicating whether VISA Electron uses Luhn validation to ensure that PAN is valid.
        See Also:
        Constant Field Values
      • VISA_ELECTRON_IS_ACTIVE

        protected static final boolean VISA_ELECTRON_IS_ACTIVE
        Constant indicating whether VISA Electron network is still being used.
        See Also:
        Constant Field Values
      • AMEX_IIN

        private static final java.lang.String[][] AMEX_IIN
        Constant containing IIN ranges reserved for American Express.
      • AMEX_LENGTH

        private static final byte[][] AMEX_LENGTH
        Constant containing valid lengths for American Express.
      • AMEX_GROUPING

        private static final byte[][] AMEX_GROUPING
        Constant defining digit groups for American Express.
      • BANKCARD_IIN

        private static final java.lang.String[][] BANKCARD_IIN
        Constant containing IIN ranges reserved for Bankcard.
      • BANKCARD_LENGTH

        private static final byte[][] BANKCARD_LENGTH
        Constant containing valid lengths for Bankcard.
      • CHINA_UNIONPAY_IIN

        private static final java.lang.String[][] CHINA_UNIONPAY_IIN
        Constant containing IIN ranges reserved for China UnionPay.
      • CHINA_UNIONPAY_LENGTH

        private static final byte[][] CHINA_UNIONPAY_LENGTH
        Constant containing valid lengths for China UnionPay.
      • DINERS_CLUB_CARTE_BLANCHE_IIN

        private static final java.lang.String[][] DINERS_CLUB_CARTE_BLANCHE_IIN
        Constant containing IIN ranges reserved for Diners Club Carte Blanche.
      • DINERS_CLUB_CARTE_BLANCHE_LENGTH

        private static final byte[][] DINERS_CLUB_CARTE_BLANCHE_LENGTH
        Constant containing valid lengths for Diners Club Carte Blanche.
      • DINERS_CLUB_ENROUTE_IIN

        private static final java.lang.String[][] DINERS_CLUB_ENROUTE_IIN
        Constant containing IIN ranges reserved for Diners Club enRoute.
      • DINERS_CLUB_ENROUTE_LENGTH

        private static final byte[][] DINERS_CLUB_ENROUTE_LENGTH
        Constant containing valid lengths for Diners Club enRoute.
      • DINERS_CLUB_ENROUTE_GROUPING

        private static final byte[][] DINERS_CLUB_ENROUTE_GROUPING
        Constant defining digit groups for Dinners club enroute.
      • DINERS_CLUB_INTERNATIONAL_IIN

        private static final java.lang.String[][] DINERS_CLUB_INTERNATIONAL_IIN
        Constant containing IIN ranges reserved for Diners Club International.
      • DINERS_CLUB_INTERNATIONAL_LENGTH

        private static final byte[][] DINERS_CLUB_INTERNATIONAL_LENGTH
        Constant containing valid lengths for Diners Club International.
      • DINERS_CLUB_INTERATIONAL_GROUPING

        private static final byte[][] DINERS_CLUB_INTERATIONAL_GROUPING
        Constant defining digit groups for Dinners club internacional. This grouping is also used for DINERS_CLUB_CARTE_BLANCHE.
      • DINERS_CLUB_USA_CA_IIN

        private static final java.lang.String[][] DINERS_CLUB_USA_CA_IIN
        Constant containing IIN ranges reserved for Diners Club USA and Canada.
      • DINERS_CLUB_USA_CA_LENGTH

        private static final byte[][] DINERS_CLUB_USA_CA_LENGTH
        Constant containing valid lengths for Diners Club USA and Canada.
      • DISCOVER_IIN

        private static final java.lang.String[][] DISCOVER_IIN
        Constant containing IIN ranges reserved for Discover.
      • DISCOVER_LENGTH

        private static final byte[][] DISCOVER_LENGTH
        Constant containing valid lengths for Discover.
      • DISCOVER_GROUPING

        private static final byte[][] DISCOVER_GROUPING
        Constant defining digit groups for Discover. This grouping is also used for all Diners Club cards.
      • INSTAPAYMENT_IIN

        private static final java.lang.String[][] INSTAPAYMENT_IIN
        Constant containing IIN ranges reserved for InstaPayment.
      • INSTAPAYMENT_LENGTH

        private static final byte[][] INSTAPAYMENT_LENGTH
        Constant containing valid lengths for InstaPayment.
      • JCB_IIN

        private static final java.lang.String[][] JCB_IIN
        Constant containing IIN ranges reserved for JCB.
      • JCB_LENGTH

        private static final byte[][] JCB_LENGTH
        Constant containing valid lengths for JCB.
      • LASER_IIN

        private static final java.lang.String[][] LASER_IIN
        Constant containing IIN ranges reserved for Laser.
      • LASER_LENGTH

        private static final byte[][] LASER_LENGTH
        Constant containing valid lengths for Laser.
      • MAESTRO_IIN

        private static final java.lang.String[][] MAESTRO_IIN
        Constant containing IIN ranges reserved for Maestro.
      • MAESTRO_LENGTH

        private static final byte[][] MAESTRO_LENGTH
        Constant containing valid lengths for Maestro.
      • MASTERCARD_IIN

        private static final java.lang.String[][] MASTERCARD_IIN
        Constant containing IIN ranges reserved for MasterCard.
      • MASTERCARD_LENGTH

        private static final byte[][] MASTERCARD_LENGTH
        Constant containing valid lengths for MasterCard.
      • MASTERCARD_GROUPING

        private static final byte[][] MASTERCARD_GROUPING
        Constant defining digit groups for Mastercard.
      • SOLO_IIN

        private static final java.lang.String[][] SOLO_IIN
        Constant containing IIN ranges reserved for Solo.
      • SOLO_LENGTH

        private static final byte[][] SOLO_LENGTH
        Constant containing valid lengths for Solo.
      • SWITCH_IIN

        private static final java.lang.String[][] SWITCH_IIN
        Constant containing IIN ranges reserved for Switch.
      • SWITCH_LENGTH

        private static final byte[][] SWITCH_LENGTH
        Constant containing valid lengths for Switch.
      • VISA_IIN

        private static final java.lang.String[][] VISA_IIN
        Constant containing IIN ranges reserved for VISA.
      • VISA_LENGTH

        private static final byte[][] VISA_LENGTH
        Constant containing valid lengths for VISA.
      • VISA_GROUPING

        private static final byte[][] VISA_GROUPING
        Constant defining digit groups for VISA.
      • VISA_ELECTRON_IIN

        private static final java.lang.String[][] VISA_ELECTRON_IIN
        Constant containing IIN ranges reserved for VISA Electron.
      • VISA_ELECTRON_LENGTH

        private static final byte[][] VISA_ELECTRON_LENGTH
        Constant containing valid lengths for VISA Electron.
      • VISA_ELECTRON_GROUPING

        private static final byte[][] VISA_ELECTRON_GROUPING
        Constant defining digit groups for VISA Electron.
      • DEFAULT_GROUPING

        private static final byte[][] DEFAULT_GROUPING
        Constant defining digit groups for any other network or unknown networks.
    • Constructor Detail

      • CreditCardValidator

        protected CreditCardValidator()
        Constructor.
    • Method Detail

      • isValidMII

        public static boolean isValidMII​(java.lang.String pan)
        Indicates if provided credit card PAN value corresponds to any valid MII (Major Industry Identifier). All valid credit card PANs must start by 3, 4, 5 or 6, which correspond to all the assigned MII.
        Parameters:
        pan - a credit card PAN value.
        Returns:
        true if PAN corresponds to a valid MII, false otherwise.
      • isValidMII

        protected static boolean isValidMII​(byte[] panDigits)
        Indicates if provided array of credit card PAN digits corresponds to any valid MII (Major Industry Identifier). All valid credit card PANs must start by 3, 4, 5 or 6, which correspond to all the assigned MII.
        Parameters:
        panDigits - an array of credit card PAN digits.
        Returns:
        true if PAN corresponds to a valid MII, false otherwise.
      • isValidationEnabledForNetwork

        public static boolean isValidationEnabledForNetwork​(CreditCardNetwork network)
        Indicates if a given credit card network uses Luhn algorithm to validate PAN values. For unknown networks validation is assumed to be disabled.
        Parameters:
        network - a credit card network.
        Returns:
        true if provided network uses PAN validation, false otherwise.
      • isNetworkActive

        public static boolean isNetworkActive​(CreditCardNetwork network)
        Indicates if provided credit card network is still being used commercially. Unknown networks are assumed to be active.
        Parameters:
        network - a credit card network.
        Returns:
        true if provided network is still being used, false otherwise.
      • detectNetworkFromPAN

        public static CreditCardNetwork detectNetworkFromPAN​(java.lang.String pan)
        Detects credit card network by using provided credit card PAN value. Detection is done by checking all known registered credit card IINs (Issuer Identification Number) against provided PAN until a match is found.
        Parameters:
        pan - a credit card PAN number.
        Returns:
        detected credit card network.
      • detectNetworkFromPAN

        protected static CreditCardNetwork detectNetworkFromPAN​(byte[] panDigits)
        Detects credit card network by using provided credit card PAN digits. Detection is done by checking all known registered credit card IINs (Issuer Identification Number) against provided PAN digits until a match is found.
        Parameters:
        panDigits - an array containing a credit card PAN digits.
        Returns:
        detected credit card network.
      • isValidLength

        public static boolean isValidLength​(java.lang.String pan)
        Detects network for provided PAN and indicates if provided credit card PAN has an appropriate length for provided credit card network.
        Parameters:
        pan - a credit card network.
        Returns:
        true if PAN has a valid length, false otherwise.
      • isValidLength

        protected static boolean isValidLength​(byte[] panDigits)
        Detects network for provided PAN digits and indicates if provided array of credit card PAN digits has an appropriate length for provided credit card network. PAN for unknown network is assumed to always have a valid length.
        Parameters:
        panDigits - an array of credit card PAN digits.
        Returns:
        true if PAN has a valid length, false otherwise.
      • isValidLength

        public static boolean isValidLength​(java.lang.String pan,
                                            CreditCardNetwork network)
        Indicates if provided credit card PAN has an appropriate length for provided credit card network. PAN for unknown network is assumed to always have a valid length.
        Parameters:
        pan - a credit card PAN.
        network - a credit card network.
        Returns:
        true if PAN has a valid length, false otherwise.
      • isValidLength

        protected static boolean isValidLength​(byte[] panDigits,
                                               CreditCardNetwork network)
        Indicates if provided array of credit card PAN digits has an appropriate length for provided credit card network. PAN for unknown networks is assumed to always have a valid length.
        Parameters:
        panDigits - an array of credit card PAN digits.
        network - a credit card network.
        Returns:
        true if PAN has a valid length, false otherwise.
      • isValid

        public static boolean isValid​(java.lang.String pan)
        Indicates if provided credit card PAN is valid by detecting its assigned credit card network, checking its length and validating its checksum if network supports validation.
        Parameters:
        pan - a credit card pan.
        Returns:
        true if credit card PAN appears to be valid, false otherwise.
      • isValid

        protected static boolean isValid​(byte[] panDigits)
        Indicates if provided credit card PAN is valid by detecting its assigned credit card network, checking its length and validating its checksum if network supports validation.
        Parameters:
        panDigits - an array containing credit card pan digits.
        Returns:
        true if credit card PAN appears to be valid, false otherwise.
      • isAmericanExpressIIN

        public static boolean isAmericanExpressIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to American Express IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to American Express, false otherwise.
      • isAmericanExpressIIN

        protected static boolean isAmericanExpressIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to American Express IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to American Express, false otherwise.
      • isAmericanExpressValidLength

        public static boolean isAmericanExpressValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for American Express cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid American Express length, false otherwise.
      • isAmericanExpressValidLength

        protected static boolean isAmericanExpressValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for American Express cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid American Express length, false otherwise.
      • isBankcardIIN

        public static boolean isBankcardIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to BankCard IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to BankCard, false otherwise.
      • isBankcardIIN

        protected static boolean isBankcardIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to BankCard IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to BankCard, false otherwise.
      • isBankcardValidLength

        public static boolean isBankcardValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for BankCard cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid BankCard length, false otherwise.
      • isBankcardValidLength

        protected static boolean isBankcardValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for BankCard cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid BankCard length, false otherwise.
      • isChinaUnionPayIIN

        public static boolean isChinaUnionPayIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to China UnionPay IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to China UnionPay, false otherwise.
      • isChinaUnionPayIIN

        protected static boolean isChinaUnionPayIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to China UnionPay IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to China UnionPay, false otherwise.
      • isChinaUnionPayValidLength

        public static boolean isChinaUnionPayValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for China UnionPay cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid China UnionPay length, false otherwise.
      • isChinaUnionPayValidLength

        protected static boolean isChinaUnionPayValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for China UnionPay cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid China UnionPay length, false otherwise.
      • isDinersClubCarteBlancheIIN

        public static boolean isDinersClubCarteBlancheIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Diners Club Carte Blanche IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Diners Club Carte Blanche, false otherwise.
      • isDinersClubCarteBlancheIIN

        protected static boolean isDinersClubCarteBlancheIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits corresponds to Diners Club Carte Blanche IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Diners Club Carte Blance, false otherwise.
      • isDinersClubCarteBlancheValidLength

        public static boolean isDinersClubCarteBlancheValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Diners Club Carte Blanche cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Diners Club Carte Blanche length, false otherwise.
      • isDinersClubCarteBlancheValidLength

        protected static boolean isDinersClubCarteBlancheValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Diners Club Carte Blanche cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Diners Club Carte Blanche length, false otherwise.
      • isDinersClubEnrouteIIN

        public static boolean isDinersClubEnrouteIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Diners Club Enroute IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Diners Club Enroute, false otherwise.
      • isDinersClubEnrouteIIN

        protected static boolean isDinersClubEnrouteIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits corresponds to Diners Club Enroute IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Diners Club Enroute, false otherwise.
      • isDinersClubEnrouteValidLength

        public static boolean isDinersClubEnrouteValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Diners Club Enroute cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Diners Club Enroute length, false otherwise.
      • isDinersClubEnrouteValidLength

        protected static boolean isDinersClubEnrouteValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Diners Club Enroute cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Diners Club Enroute length, false otherwise.
      • isDinersClubInternationalIIN

        public static boolean isDinersClubInternationalIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Diners Club International IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Diners Club International, false otherwise.
      • isDinersClubInternationalIIN

        protected static boolean isDinersClubInternationalIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits corresponds to Diners Club International IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Diners Club International, false otherwise.
      • isDinersClubInternationalValidLength

        public static boolean isDinersClubInternationalValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Diners Club International cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Diners Club International length, false otherwise.
      • isDinersClubInternationalValidLength

        protected static boolean isDinersClubInternationalValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Diners Club International cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Diners Club International length, false otherwise.
      • isDinersClubUSACanadaIIN

        public static boolean isDinersClubUSACanadaIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Diners Club USA and Canada IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Diners Club USA and Canada, false otherwise.
      • isDinersClubUSACanadaIIN

        protected static boolean isDinersClubUSACanadaIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits corresponds to Diners Club USA and Canada IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Diners Club USA and Canada, false otherwise.
      • isDinersClubUSACanadaValidLength

        public static boolean isDinersClubUSACanadaValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Diners Club USA and Canada cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Diners Club USA and Canada length, false otherwise.
      • isDinersClubUSACanadaValidLength

        protected static boolean isDinersClubUSACanadaValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Diners Club USA and Canada cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Diners Club USA and Canada length, false otherwise.
      • isDiscoverIIN

        public static boolean isDiscoverIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Discover IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Discover, false otherwise.
      • isDiscoverIIN

        protected static boolean isDiscoverIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits corresponds to Discover IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Discover, false otherwise.
      • isDiscoverValidLength

        public static boolean isDiscoverValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Discover cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Discover length, false otherwise.
      • isDiscoverValidLength

        protected static boolean isDiscoverValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Discover cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Discover length, false otherwise.
      • isInstaPaymentIIN

        public static boolean isInstaPaymentIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to InstaPayment IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to InstaPayment, false otherwise.
      • isInstaPaymentIIN

        protected static boolean isInstaPaymentIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits corresponds to InstaPayment IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to InstaPayment, false otherwise.
      • isInstaPaymentValidLength

        public static boolean isInstaPaymentValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for InstaPayment cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid InstaPayment length, false otherwise.
      • isInstaPaymentValidLength

        protected static boolean isInstaPaymentValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for InstaPayment cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid InstaPayment length, false otherwise.
      • isJCBIIN

        public static boolean isJCBIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to JCB IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to JCB, false otherwise.
      • isJCBIIN

        protected static boolean isJCBIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to JCB IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to JCB, false otherwise.
      • isJCBValidLength

        public static boolean isJCBValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for JCB cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid JCB length, false otherwise.
      • isJCBValidLength

        protected static boolean isJCBValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for JCB cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid JCB length, false otherwise.
      • isLaserIIN

        public static boolean isLaserIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Laser IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Laser, false otherwise.
      • isLaserIIN

        protected static boolean isLaserIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to Laser IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Laser, false otherwise.
      • isLaserValidLength

        public static boolean isLaserValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Laser cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Laser length, false otherwise.
      • isLaserValidLength

        protected static boolean isLaserValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Laser cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Laser length, false otherwise.
      • isMaestroIIN

        public static boolean isMaestroIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Maestro IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Maestro, false otherwise.
      • isMaestroIIN

        protected static boolean isMaestroIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to Maestro IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Maestro, false otherwise.
      • isMaestroValidLength

        public static boolean isMaestroValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Maestro cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Maestro length, false otherwise.
      • isMaestroValidLength

        protected static boolean isMaestroValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Maestro cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Maestro length, false otherwise.
      • isMastercardIIN

        public static boolean isMastercardIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Mastercard IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Mastercard, false otherwise.
      • isMastercardIIN

        protected static boolean isMastercardIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to Mastercard IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Mastercard, false otherwise.
      • isMastercardValidLength

        public static boolean isMastercardValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Mastercard cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Mastercard length, false otherwise.
      • isMastercardValidLength

        protected static boolean isMastercardValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Mastercard cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Mastercard length, false otherwise.
      • isSoloIIN

        public static boolean isSoloIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Solo IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Solo, false otherwise.
      • isSoloIIN

        protected static boolean isSoloIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to Solo IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Solo, false otherwise.
      • isSoloValidLength

        public static boolean isSoloValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Solo cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Solo length, false otherwise.
      • isSoloValidLength

        protected static boolean isSoloValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Solo cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Solo length, false otherwise.
      • isSwitchIIN

        public static boolean isSwitchIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to Switch IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to Switch, false otherwise.
      • isSwitchIIN

        protected static boolean isSwitchIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to Switch IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to Switch, false otherwise.
      • isSwitchValidLength

        public static boolean isSwitchValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for Switch cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid Switch length, false otherwise.
      • isSwitchValidLength

        protected static boolean isSwitchValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for Switch cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid Switch length, false otherwise.
      • isVISAIIN

        public static boolean isVISAIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to VISA IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to VISA, false otherwise.
      • isVISAIIN

        protected static boolean isVISAIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to VISA IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to VISA, false otherwise.
      • isVISAValidLength

        public static boolean isVISAValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for VISA cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid VISA length, false otherwise.
      • isVISAValidLength

        protected static boolean isVISAValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for VISA cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid VISA length, false otherwise.
      • isVISAElectronIIN

        public static boolean isVISAElectronIIN​(java.lang.String pan)
        Indicates if provided credit card PAN corresponds to VISA Electron IIN (Issuer Identification Number).
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if provided PAN corresponds to VISA Electron, false otherwise.
      • isVISAElectronIIN

        protected static boolean isVISAElectronIIN​(byte[] panDigits)
        Indicates if provided credit card PAN digits correspond to VISA Electron IIN (Issuer Identification Number).
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if provided PAN corresponds to VISA Electron, false otherwise.
      • isVISAElectronValidLength

        public static boolean isVISAElectronValidLength​(java.lang.String pan)
        Indicates if provided credit card PAN has valid length for VISA Electron cards.
        Parameters:
        pan - a credit card PAN.
        Returns:
        true if PAN has a valid VISA Electron length, false otherwise.
      • isVISAElectronValidLength

        protected static boolean isVISAElectronValidLength​(byte[] panDigits)
        Indicates if provided credit card PAN digits have valid length for VISA Electron cards.
        Parameters:
        panDigits - array containing credit card PAN digits.
        Returns:
        true if PAN has a valid VISA Electron length, false otherwise.
      • isValidChecksumForPAN

        public static boolean isValidChecksumForPAN​(java.lang.String pan)
        Validates provided credit card PAN using Luhn algorithm assuming that the last digit of provided PAN corresponds to its checksum value. This method computes the checksum value using Luhn algorithm and compares that with the last digit of provided PAN value, if both are equal PAN checksum is assumed to be valid.
        Parameters:
        pan - a credit card PAN to validate its checksum.
        Returns:
        true if checksum is valid, false otherwise.
      • isValidChecksumForPAN

        protected static boolean isValidChecksumForPAN​(byte[] panDigits)
        Validates provided credit card PAN using Luhn algorithm assuming that the last digit of provided PAN corresponds to its checksum value. This method computes the checksum value using Luhn algorithm and compares that with the last digit of provided PAN digits, if both are equal PAN checksum is assumed to be valid.
        Parameters:
        panDigits - array of digits containing a credit card PAN.
        Returns:
        true if checksum is valid, false otherwise.
      • toDigits

        public static byte[] toDigits​(java.lang.String pan)
        Converts a credit card PAN from its string representation into an array containing PAN digits. This method will strip away any spaces or punctuation marks, leaving only the digits found within provided PAN.
        Parameters:
        pan - a credit card PAN.
        Returns:
        credit card PAN represented as an array of digits.
      • isValidIIN

        protected static boolean isValidIIN​(java.lang.String pan,
                                            java.lang.String[][] iins)
        Internal method to check whether provided credit card PAN corresponds to a valid IIN by checking the array of valid IIN ranges.
        Parameters:
        pan - a credit card PAN.
        iins - array of valid IIN ranges.
        Returns:
        true if PAN corresponds to a valid IIN, false otherwise.
      • isValidIIN

        protected static boolean isValidIIN​(byte[] panDigits,
                                            java.lang.String[][] iins)
        Internal method to check whether provided array of PAN digits corresponds to a valid IIN by checking the array of valid IIN ranges.
        Parameters:
        panDigits - array containing credit card PAN digits.
        iins - array of valid IIN ranges.
        Returns:
        true if PAN corresponds to valid IIN, false otherwise.
      • isValidLength

        protected static boolean isValidLength​(java.lang.String pan,
                                               byte[][] lengths)
        Internal method to determine whether length of provided credit card PAN is valid based on array of valid length ranges.
        Parameters:
        pan - a credit card PAN.
        lengths - array of valid length ranges.
        Returns:
        true if PAN length is valid, false otherwise.
      • isValidLength

        protected static boolean isValidLength​(byte[] panDigits,
                                               byte[][] lengths)
        Internal method to determine whether length of provided array of credit card PAN digits is valid based on array of valid length ranges.
        Parameters:
        panDigits - array containing credit card PAN digits.
        lengths - array of valid length ranges.
        Returns:
        true if PAN length is valid, false otherwise.
      • numLeadingZeros

        protected static int numLeadingZeros​(java.lang.String iin)
        Computes number of leading zeros on any given IIN.
        Parameters:
        iin - a given IIN in string format.
        Returns:
        number of leading zeros.
      • computeCheck

        protected static byte computeCheck​(byte[] digitsWithoutCheck)
        Computes checksum using Luhn algorithm. Notice that this method will modify the values in provided array of digits.
        Parameters:
        digitsWithoutCheck - array containing a credit card PAN number without its checksum value (which is the last digit).
        Returns:
        computed checksum value.
      • groupingsForNetwork

        protected static byte[][] groupingsForNetwork​(CreditCardNetwork network)
        Returns credit card digit groupings for provided credit card network.
        Parameters:
        network - a credit card network.
        Returns:
        digit groupings.
      • getNumberOfGroupsForNetwork

        public static int getNumberOfGroupsForNetwork​(CreditCardNetwork network)
        Returns number of digit groups for provided credit card network.
        Parameters:
        network - a credit card network.
        Returns:
        number of digit groups for provided credit card network.
      • getMinDigitsForGroupAndNetwork

        public static int getMinDigitsForGroupAndNetwork​(int groupPos,
                                                         CreditCardNetwork network)
        Returns minimum number of required digits for provided group position (starting at zero until the maximum number of groups minus one).
        Parameters:
        groupPos - position of group of digits.
        network - credit card network.
        Returns:
        minimum number of required digits.
        Throws:
        java.lang.IllegalArgumentException - if groupPos is negative or exceeds the maximum number of groups minus one for provided credit card network.
      • getMaxDigitsForGroupAndNetwork

        public static int getMaxDigitsForGroupAndNetwork​(int groupPos,
                                                         CreditCardNetwork network)
        Returns maximum number of allowed digits for provided group position (starting at zero until the maximum number of groups minus one).
        Parameters:
        groupPos - position of group of digits.
        network - credit card network.
        Returns:
        maximum number of allowed digits.
        Throws:
        java.lang.IllegalArgumentException - if groupPos is negative or exceeds the maximum number of groups minus one for provided credit card network.