How To Limit Android Edit Text Field Only For Some Selected Characters
Solution 1:
Use the digits
attribute, only the characters passed to digits
will be allowed in the EditText.
android:digits="abc123"
And yes, "digits" is a misleading name, it accepts letters and symbols too.
Solution 2:
You can use the inputType
attribute:
<EditText android:id="@+id/edit_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" />
Possible Values for android:inputType
attribute in edit text are: none, text, textCapCharacters, textCapWords, textCapSentences, textAutoCorrect, textAutoComplete, textMultiLine, textImeMultiLine, textNoSuggestions, textUri, textEmailAddress, textEmailSubject, textShortMessage, textLongMessage, textPersonName, textPostalAddress, textPassword, textVisiblePassword, textWebEditText, textFilter, textPhonetic, textWebEmailAddress, textWebPassword, number, numberSigned, numberDecimal, numberPassword, phone, datetime, date, time
Solution 3:
This android:digit
will allow only the digits and alphabets you want to be filled in EditText.
<EditTextandroid:inputType="text"android:digits="0123456789*qwertzuiopasdfghjklyxcvbnm,_,-"android:hint="Only letters, digits, _ and - allowed"
/>
Solution 4:
You can set your EditText Field like this...
<EditTextandroid:inputType="text"android:digits="THE SELECTED CHARACTERS THAT USERS ARE ALLOWED TO TYPE"
/>
By listing the selected characters (A,B,C,and D) that users are allowed to type in the android:digits, you are limiting the possible characters that users can type. This is the easiest way I've learned through searching.
Post a Comment for "How To Limit Android Edit Text Field Only For Some Selected Characters"