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
Developer
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10
My Carrier: Aircel
Accepted Solution

Restrict the keyboard entry.

Hi All

 

I want to do like this:

 

I have one Text field i want to enter only alphabates values in this field and if i change my keypad and try to enter other than alphabates like number, special character it will not print in the field and as well as i also want to define its maximum length.

 

Is it possible or not?

 

Please provide any suggestion for this ASAP please its urgent.

 

Thanks in advance.

 

Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Restrict the keyboard entry.

Did you looked at API documentation ? Especially inputMode property

https://developer.blackberry.com/cascades/reference/bb__cascades__textfield.html#inputmode

Also Validator but seems that there are no docs about its usage.
Contributor
Posts: 43
Registered: ‎01-05-2013
My Device: Dev Alpha
My Carrier: Telenor Hungary

Re: Restrict the keyboard entry.

Hi,

textfield has a signal: onTextChanging

This will emitted, when the text is changing. You can filter the input characters in this method one by one. If the input character is not an alphabet, just remove it from the textfield's text property.
--------------------------------------------------------------
If my post was helpful or it was the solution for Your problem, please don't forget to give me a like, and mark my post as a solution. Thanks!
Contributor
Posts: 43
Registered: ‎01-05-2013
My Device: Dev Alpha
My Carrier: Telenor Hungary

Re: Restrict the keyboard entry.

Here is an example with regular expressions:

http://blackberry.github.com/Qt2Cascades-Samples/docs/tools-regexp.html
--------------------------------------------------------------
If my post was helpful or it was the solution for Your problem, please don't forget to give me a like, and mark my post as a solution. Thanks!
Developer
Posts: 19
Registered: ‎03-04-2012
My Device: Playbook 2.0
My Carrier: Vodafone

Re: Restrict the keyboard entry.

that was posted a while ago in this forum and I use it in some of my apps, but I'm now unable to find the exact post :smileysad:

 

It's not perfect (and it deals with numbers instead of alphabets, an easy change) but it might be useful as a general idea.

 

function numericOnly (textin) {
             
                 var m_strOut = new String (textin);
                 m_strOut = m_strOut.replace(/[^\d.]/g,'');
                 
                 return m_strOut;
                                     
            }

onTextChanging: {
    txtAmount.text = rootContainer.numericOnly(text);
}