I want to make a BasicEditField that should accept only uppercase letters, lowercase letters and numeric values. It should not accept any other symbol. Is there any style bit available for BlackBerry BasicEditField that makes it work this way? If not, is there anything else I can do?
I use these methods: TextFilter#get and BasicEditField#setFilter
mEdit = new EditField();
mEdit.setFilter(TextFilter.get(TextFilter.NUMERIC));
or
// Numeric filter that also allows minus sign.
mEdit.setFilter(TextFilter.get(TextFilter.INTEGER));
I think creating your own filter by overriding TextFilter can solve more difficult filtering task.
Perhaps it is not possible to combine them like that then, I didn't try it. Whenever I have used filters in my code I have always done it the second way I mentioned above. It is a bit more complicated but gives you a lot more control over what the field can and cannot accept. Check out the API documentation on the TextFilter class. As I said above you would just have to implement the convert and validate methods. I think in your case you wouldn't have to do anything in convert. But in the validate method you would just have to check that the character is in the range a-z A-Z or 0-9. If it is return true, otherwise return false. This will stop all unwanted characters from appearing in the field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With