-
Notifications
You must be signed in to change notification settings - Fork 2
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
- Luhn Verification Algorithm
- Smooth UI
- Info about card details
- Credit Card Type Prediction
- By this control detects the following card types:
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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"
}
}
}