How to force EditText to accept only specific alphanumerical characters?

倖福魔咒の 提交于 2019-12-08 10:12:17

问题


I want from my EditText to accept only certain characters. I don`t want to filter them in listener, I want to set it in XML permanently.

I want to use only these characters: 0123456789abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ

So I made string and add that to android:digits. I want to convert each lowercase letter to uppercase (I dont want to disable typing without shift just convert them)

I used android:textAllCaps="true" but this doesnt work.


回答1:


Try this, This will help you for sure.

 editText.setFilters(new InputFilter[] {new InputFilter.AllCaps()});



回答2:


You can do it in XML file

 android:digits="0123456789abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ"

Possible duplicate: How to restrict the EditText to accept only alphanumeric characters



来源:https://stackoverflow.com/questions/56495984/how-to-force-edittext-to-accept-only-specific-alphanumerical-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!