I am developing an application for keyboard, but i am geting an issue. I want to restrict/block some special character from soft keyboard in EditText in android programmatically.
So, Is there any way i can restrict any special character input in edit text in android.
If anyone have idea,Please reply.
Thanks in advance.
If you want to add spaces you can give space after the last digit.
check this link which shows How to restrict special characters from an Android EditText field?
Try this code
android:digits="abcde.....012345789"
i guess this is the easiest way to do.Hope this help you.First need to add DigitsKeyListener for allowing characters and then setRawInputType to edittext field
You can create regular expression and check it on onTextChanged method
Unfortunately the accepted solution doesn't work in all the cases. The proper solution would be to use the following
InputFilter
:This solution differs from the accepted one in that it solves the following problems:
For those who might be facing issues while adding space please add a blank space with all the alphabets. Below is an example Also you should know that user won't be able to add a new line in this case.