How to restrict special characters from an Android EditText field?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I have solved this problem in my answer: Prevent special symbols in EditText. You can change the regex as per your requirement.
Just pass the EditText object to this method. Also add the values that is to be blocked in the variable blockCharacterSet.
Have you tried adding the
android:digits="abcde.....0123456789"
attribute? Although theandroid:digits
specify that it is a numeric field, it does work for me to set it to accept letters as well, and special characters as well (tested on SDK-7).If this doesn't work then you'll have to implement
KeyListener
see: http://developer.android.com/reference/android/widget/TextView.html#setKeyListener(android.text.method.KeyListener)