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

Posts: 692
Registered: ‎08-09-2010
My Device: Not Specified
Accepted Solution

How to put validation into TextField?

Hi All,


    I set numeric keyboard into TextField then i also enter sepcial caracter and character . So may i know how to validate TextField??



Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to put validation into TextField?

as you cannot validate between the user input and the field receiving the input you have to do it when the field gets it, for example in onTextChanging.
I save the old text, check if the new is valid (with regex) and replace the new with the old if it was not valid.

the native apps seem to do the same, you can see a quick flickering with a letter being shown, then deleted.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: How to put validation into TextField?

To validiate the text the user has entered and mark it as such, you can use the Validator api: https://developer.blackberry.com/native/reference/cascades/bb__cascades__validator.html


This won't prevent them from entering special characters, but it can help you ensure that the string they have entered is in the format you want. You can't actually prevent them from entering certain characters other than by using a method like the one suggested by Simon.


Note that even though you can customize the virtual keyboard, users with a QWERTY device like the Q10, or with a bluetooth keyboard, will be able to just type any keys they feel like.

Paul Bernhardt
Application Development Consultant

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker