Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper inputType for Credit Cards

Tags:

android

I'm trying to devise an input type for a field which will accept credit card numbers.

I had been using inputType="number" - but that won't let people with hardware keyboards hit the space bar.. when they do it jumps to another field in the activity.

I'd like to allow users to use a space in their numbers if they want, or, at least, make it so that if users with a hardware keyboard hit the space when I'm only allowing numbers it won't leave the credit card number EditText.

Ideally I'd be able to implement some interface and have my own custom inputType, but I'm not sure that's possible.

  • Is it possible to allow numbers and spaces, while showing the numbers soft keyboard?
like image 430
Matthew Runo Avatar asked Nov 10 '11 22:11

Matthew Runo


People also ask

What is the correct input type for credit card numbers?

Therefore, if the user is typing a VISA or MasterCard card number, the input should be auto-formatted to include a space for every fourth digit.

How many digits should a card have?

Credit card numbers are usually made of 16 digits arranged in sets of four. American Express numbers contain 15 digits. Though rare, some credit card companies employ 19 digits.


2 Answers

The best choise is InputType.TYPE_CLASS_DATETIME

like image 146
Mickey Tin Avatar answered Sep 18 '22 14:09

Mickey Tin


How about android:inputType="phone" in your layout xml file?

like image 37
Giorgos Kylafas Avatar answered Sep 18 '22 14:09

Giorgos Kylafas