EditText Input type Issue - android

There is a name EditText in my screen. I want to accept only alphabets means from a-z,A-Z
and should not accept numbers, special chars.
I'am using inputtype="textPersonName" for that but its notworking, it accepts means showing all numbers, chars etc..
For phone field inputtype="phone" is working it accepting means showing numbers in field` only.
Why like that?

Your best bet is to use an InputFilter to restrict the characters that are permitted in your EditText control. You should be able to easily adapt the answer from How do I use InputFilter to limit characters in an EditText in Android? to do what you require.

You will need to subclass EditText and detect key events.
Reject any character other than a-zA-Z
This is the only way to limit the acceptable characters.
A person's name could contain a number so textPersonName is working correctly.

Try using TYPE_TEXT_VARIATION_PHONETIC

Related

Is it possible to set EditText only accept unicode characters in android?

Is it possible to make an android EditText accept only unicode characters? If so, how?
Currently, unicode only is not a restriction option for the EditText component, but you can dynamically check every symbol to see if it falls into that category or not, and if not remove it.

How to set EditText input type like "X123"?

I want to enter the text in the format of "X123". i.e first letter is alphatbetical and remaining should be numericals. So is there any input type which fullfill this requirement or I have to use textwatcher for edit text and then change input type of edit text at run time.Is it possible?
Thanks in advance.
There is no standard input type like this.
You can use TextWatcher if you want to force it upon your users while typing, but that might not really be nice neither. You'll only get the effect that they press 'wrong' input and nothing happens.
Perhaps its a much easier, and still nicer way to simply put in a hint which shows the expected input, and once they 'submit' the input you check it against a regex.
If it doesn't match the regex, you can show a Toast, shake the input field, surround the edittext with red lines or whatever you want to show what field has wrong input.
use this RegExp to match the string
string.matches("[a-zA-Z]\\d{3,}") // for compulasory one char and min three digit
string.matches("[a-zA-Z]\\d{2,}") // for compulasory one char and min two digit
string.matches("[a-zA-Z]\\d{1,}") // for compulasory one char and min one digit
string.matches("[a-zA-Z]\\d*") // for compulasory one char and zero or more digit
Hope it will help you.

Android EditText accept 2 values only

I want an EditText to accept two characters only, a one(1) and a zero(0). I was reading about input filters and know how to accept numeric values only but what about specifying which characters to accept.
Can someone please give me an example as to how this is done?
You may need to use something like TextWatcher, inside TextWathcer onTextChanged, if entered value is not either 1,0 display message.

Input Type Number, no negative sign or decimals allowed?

I have two edittext views that I using for a calculation and both need to be limited to numbers only so I'm using the InputType to do this, but now I cannot enter a negative number or any numbers containing decimals!
Any ideas or solutions?
Thanks!
You should use numberSigned or numberDecimal, or both numberDecimal|numberSigned to enable features you need.
Simply use the below and even the device input keyboard will contain numbers only:
myTextView.setInputType(
InputType.TYPE_CLASS_NUMBER);

How do I open numeric keypad when edittext selected and input multiple numbers? inputStyle="number" limits the quantity of numbers to one

I am making a math program that reads in numbers from an edittext box, and creates / LU factors a matrix. When a user clicks into this field, the regular keyboard shows. It would be easier for the user if it were a numeric keyboard. When I use android:inputStyle="number" the amount of numbers allowed to be entered into the field is 1. How do I bring up the numeric keyboard without limiting the ability to enter multiple numbers?
Add this in each numeric edittext in your layout file:
android:numeric="decimal"
android:numeric has been depreciated. (From Google: android:numeric If set, specifies that this TextView has a numeric input method. * Deprecated: Use inputType instead.)
android:inputType="number" seems to work great for me. There are a lot of options as well. (From Google: The type of data being placed in a text field, used to help an input method decide how to let the user enter text.)
android:inputType="numberDecimal"

Categories

Resources