Skip to content

Credit Card EditText

kevadiya krunal edited this page Mar 14, 2019 · 1 revision
  • Smooth UI for Credit Card Entry on Android device, perform check for supported credit card types , pan length and luhn check. Inspired by Uber credit card entry interface
  1. Luhn Verification Algorithm
  2. Smooth UI
  3. Info about card details
  4. Credit Card Type Prediction
  • By this control detects the following card types:
  1. American Express
  • has to start with any digit of "34, 37".
  • has card number length is 15.
  • has support pin type CID and length is 4 digit.
  1. Card Guard
  • has to start with any digit of "5392".
  • has card number length is 16.
  • has support pin type CVV and length is 3 digit.
  1. China Union Pay
  • has to start with any digit of "62".
  • has card number length is 16-19.
  • has support pin type CVN and length is 3 digit.
  1. Dankort
  • has to start with any digit of "5019".
  • has card number length is 16.
  • has support pin type CVV and length is 3 digit.
  1. Diners Club
  • has to start with any digit of "300-305, 309, 36, 38, 39".
  • has card number length is 14,16-19.
  • has support pin type CVV and length is 3 digit.
  1. Discover
  • has to start with any digit of "6011, 622126 to 622925, 644, 645, 646, 647, 648, 649, 65".
  • has card number length is 16,19.
  • has support pin type CID and length is 3 digit.
  1. Insta Payment
  • has to start with any digit of "637, 638, 639".
  • has card number length is 16.
  • has support pin type CVV and length is 3 digit.
  1. JCB
  • has to start with any digit of "3528-3589".
  • has card number length is 16-19.
  • has support pin type CVV and length is 3 digit.
  1. Maestro
  • has to start with any digit of "5018, 5020, 5038, 5893, 6304, 6759, 6761, 6762, 6763".
  • has card number length is 12-19.
  • has support pin type CVC and length is 3 digit.
  1. Master
  • has to start with any digit of "51, 52, 53, 54, 55, 222100-272099".
  • has card number length is 16.
  • has support pin type CVC and length is 3 digit.
  1. Mir
  • has to start with any digit of "2200 - 2204".
  • has card number length is 16.
  • has support pin type CVP and length is 3 digit.
  1. Troy
  • has to start with any digit of "979200-979289".
  • has card number length is 16.
  • has support pin type CVV and length is 3 digit.
  1. Universal Air Travel Plan
  • has to start with any digit of "1".
  • has card number length is 15.
  • has support pin type CVV and length is 3 digit.
  1. Verve
  • has to start with any digit of "506099-506198, 650002-650027".
  • has card number length is 16,19.
  • has support pin type CVV and length is 3 digit.
  1. Visa Electron
  • has to start with any digit of "4026, 417500, 4508, 4844, 4913, 4917".
  • has card number length is 16.
  • has support pin type CVV and length is 3 digit.
  1. Visa
  • has to start with any digit of "4".
  • has card number length is 13,16,19.
  • has support pin type CVV and length is 3 digit.

How to use

  • Add the EditText in your layout file and customize it the way you like it.
<com.kotlinlibrary.creditcardview.CardTextInputLayout
            android:id="@+id/edt_card_number"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_30sdp"
            app:errorEnabled="false"
            app:hintEnabled="false"
            app:passwordToggleEnabled="false"
            app:passwordToggleTint="@null">

        <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:background="@null"
                android:drawablePadding="@dimen/_5sdp"
                android:hint="@string/app_name"
                android:imeOptions="actionDone"
                android:inputType="text"
                android:padding="@dimen/_5sdp"
                android:drawableEnd="@drawable/payment_ic_generic"
                android:textColor="@color/design_default_color_primary"
                android:textColorHint="@color/black_transparent"
                android:textSize="@dimen/_16ssp"/>

</com.kotlinlibrary.creditcardview.CardTextInputLayout>
  • Then, instanciate the EditText
val edtCardNumber: CardTextInputLayout by lazy {
    findViewById<CardTextInputLayout>(R.id.edt_card_number)
}
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(...)

        edtCardNumber.post {
            edtCardNumber.editText?.addTextChangedListener(object : CardNumberTextWatcher(edtCardNumber) {
                override fun onValidated(moveToNext: Boolean, cardPan: String, cardInfo: Card?) {
                    //Here, you have get all info of card detail.
                }
            })
        }

        findViewById<Button>(R.id.btn_submit).setOnClickListener {
            if (edtCardNumber.hasValidInput()) {
                //"cart number valid"
            } else {
               //"cart number invalid"
            }
        }
    }

Clone this wiki locally