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: 692
Registered: ‎08-09-2010
My Device: Not Specified

How to validate text field only character and number???

Hello All,

 

  I try below code but not get sucess more

 

  

 function numericCharacterOnly (textin) {
        console.log("Test..."+textin);
        var m_strOut = new String (textin);
        m_strOut = m_strOut.replace(/[-=+:;'"()?!@#$%^*_|]/,'');
        
        return m_strOut;
    
 } // end numericOnly

    

   I can still enter some special character which you show below images so let me know how can  i put condition for textfield accpet only character and number???

 

   

      2013-11-20_0011.png

    

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to validate text field only character and number???

you can only filter entered characters out so that they don't appear on screen (or only for a very short time).
----------------------------------------------------------
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
Developer
Posts: 692
Registered: ‎08-09-2010
My Device: Not Specified

Re: How to validate text field only character and number???

Hi Simon,

 

   Can you explain more or provide some example??

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to validate text field only character and number???

i have a textfield with a property textEntered.
i use onTextChanging to validate the entered text, if it does not match i replace the text from c++.
I use blockSignals to avoid a loop.
----------------------------------------------------------
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
Developer
Posts: 692
Registered: ‎08-09-2010
My Device: Not Specified

Re: How to validate text field only character and number???

Hi Simon,

  

     I already do code which i mention my previous post but query for that how to add special character condition because some character not mention into our keyboard.

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to validate text field only character and number???

I use regular expressions to filter my input. There are plenty of websites that allow you to create regular expressions if you are not that experienced with them.

an example for numeric only:
QRegExp regEx = QRegExp("[0-9]*");
if (!regEx.exactMatch(textFromTheField)){
----------------------------------------------------------
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