tags:

views:

561

answers:

2

i m having basiceditfield.I want to make that field should accept only Uppercase letter ,lowercase letter and Numeric values.It should not accept any other symbol.Is any style available in blackberry basiceditfield method to make it like this or else how to handle this situation.

+1  A: 

There is a constructor that allows you to specify the style of the field. You can then OR together the styles you want, like FILTER_UPPERCASE | FILTER_LOWERCASE | FILTER_NUMERIC.

Alternatively you can call setFilter and create your own subclass of TextFilter, which allows you to specify the exact behaviour you want by overwriting the convert and validate methods. Convert allows you to force certain things like automatically make all text entered uppercase etc. Validate allows you to block certain things from being entered, e.g. special characters. Check out the API for more information.

DaveJohnston
Hi Dave i tried "FILTER_UPPERCASE | FILTER_LOWERCASE | FILTER_NUMERIC" this one, but i consider the first filter only ex.in the above style ur given uppercase,lowercase and numeric.But the filter is accepting only uppercase only.
Kumar
A: 

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.

DaveJohnston