Hi I want to show only numbers and characters on the keypad for EditText in android, I did try to add the attribute android:inputType = text|number
but it did not work.
Please help me with any other better suggestion. thanks in advance.
Hi I want to show only numbers and characters on the keypad for EditText in android, I did try to add the attribute android:inputType = text|number
but it did not work.
Please help me with any other better suggestion. thanks in advance.
Use the filter for that. Here I am adding the code for filter.
Its Working Restrict Special Symbol in Edittext
The expected solution is to restrict user from entering special characters from keyboard.
The below solution uses RegX but adds it to strings.xml file so that will be taken care at the time of creating multilingual xmls.
Strings.xml
Source file
Hope this will solve the prob. for new guys. :)
The solution with
InputFilter
provided here is not 100% correct as it will replace and throw out some valid characters from the input if they are right next to the invalid one.For example we need to filter out all special characters and you enter text: olala[
The EditText field will pass the whole
olala[
sentence to the filter and the return value will be "" meaning that we throw out valid olala as well.Here is my solution:
We need double loop here to avoid memory allocation of StringBuilder for every method call with valid characters.
try to add the digits parameter to your editText: