Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit Android edit text field only for some selected characters

Is there any way to limit users allowed to type only some selected character set (Eg: A or B or C or D) in Android layout.xml

like image 946
Grant Avatar asked Nov 17 '12 17:11

Grant


People also ask

How do I stop deleting the first character of edit text android?

First, you can simply have it so that if the EditText block is empty, it is immediately repopulated with a "/" char. Alternatively, make it so that if the previous char is / , then prevent the user from deleting back.

How do I turn off edit text on android?

What should I set to disable EditText? It's possible to preserve both the style of the view and the scrolling behaviour. To disable an EditText while keeping this properties, just use UI. setReadOnly(myEditText, true) from this library.


2 Answers

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.

like image 125
Sam Avatar answered Sep 21 '22 18:09

Sam


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

like image 44
RajeshVijayakumar Avatar answered Sep 18 '22 18:09

RajeshVijayakumar