Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
Posts: 2
Registered: ‎01-02-2013
My Device: 9800
My Carrier: Rogers

TextField validation

What's the canonical way to validate the contents of a TextField as the user types? For example in one field I want the user to be allowed to enter integer values from 0 to 99. In another text field only valid decimal values from -10.0 to +10.0. So I want to prevent the user from entering invalid characters, and also in the correct  ranges.

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: TextField validation

I'm not sure there's anything "canonical" yet and, since there's no built-in support for filtering like that, your only option appears to be hooking into onTextChanging and attempting to modify the field on-the-fly (or possibly the event can be cancelled when appropriate?).

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 103
Registered: ‎12-31-2012
My Device: Blackberry 9810
My Carrier: Verizon

Re: TextField validation

Even i feel the same... I had been looking around for something similar for a while and ended up using the onTextChanging event.

Developer
Posts: 889
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha
My Carrier: Verizon

Re: TextField validation

New Contributor
Posts: 2
Registered: ‎01-02-2013
My Device: 9800
My Carrier: Rogers

Re: TextField validation

I had tried validating the text using onTextChanging, but what I see happening is when the user enters an invalids character it temporarily appears on screen before I remover it which is undesired. Any way to hook in earlier Like on key press?