Reputation: 10636
I want an EditText to contain exactly 8 digits (like bank accounts). Of course in addition to :
android:inputType="number"
Is there an option in XML or do I have to manage this programmatically ?
Upvotes: 0
Views: 2703
Reputation: 4301
Programmatically.
Also, you can save time by using existing library EditText with validation. You can use a regex
type with following pattern [0-9]{8}
.
Upvotes: 1
Reputation: 2657
This is my phone edit text:
<EditText
style="@style/ObligatoryEditTextStyle"
android:id="@+id/etxtClientPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:gravity="left"
android:textColor="@color/hub_blue_normal"
android:visibility="visible"
android:selectAllOnFocus="true"
android:digits="0123456789"
android:maxLength="8"/>
Tell me if I helped you and good programming!!
Upvotes: 0
Reputation: 324
Change input type in decimal, then set maxLength="8".
android:inputType="decimal"
android:maxLength="8"
Upvotes: -1
Reputation: 2981
I think there is no way just in xml. You have to validate it programmatically.
@Override
public void afterTextChanged(Editable s) {
// validation code goes here
}
Upvotes: 1