Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (keyboard)
Viewing all articles
Browse latest Browse all 352

Blocking characters from being input in textfield

$
0
0

Sorry but i need your expertise once again.

I need to be assure that the user can only type numbers on runtime or before the input is finished. Changing the keyboard to numpad isn't enough since it allows user to put spaces and plus and minus symbols on Android, and on Iphone it is possible to change the keyboard type.

I was trying to catch the event onChange but for some reason, even with a control variable, it goes into a cyclic loop.

Is it possible to block characters from the keyboard even before they are introduced into the textfield?

I've created an inputControll to save the history of the textfield value.

I've also tried to add a control variable to Alloy.Globals without success, but its not included in the code below.

.js

var inputControll = "";
 
function validateOnChange()
{
     if ($.txt_tlm.value != inputControll )
     {
        inputControll = ($.txt_tlm.value).replace(/[^0-9]+/,"");
        $.txt_tlm.value = inputControll;
        $.txt_tlm.setSelection($.txt_tlm.value.length, $.txt_tlm.value.length);
    } 
}

Viewing all articles
Browse latest Browse all 352


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>