user3472001 user3472001 - 5 months ago 90
Android Question

How to restrict the EditText to accept only alphanumeric characters

How can I restrict an

EditText
to accept only alphanumeric characters, with both lowercase and uppercase characters showing as uppercase in the
EditText
?

<EditText
android:id="@+id/userInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="3" >

<requestFocus />
</EditText>


If a user types in lowercase "abcd", the
EditText
should automatically show uppercase "ABCD" without needing to restrict the keyboard to uppercase.

Answer

In the XML, add this:

 android:digits="abcdefghijklmnopqrstuvwxyz1234567890 "