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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

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: 17,025
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