:: Forum >> Version 2 >>

Input control: how to filter keyboard

With the Input control, how would one filter keyboard input?

For example, I have an Input control and I want to only allow the number keys '0' through '9'.

Is there a way I can cancel the event so that only keystrokes '0' through '9' would appear in the Input control?

Eric Juvet
Thursday, January 31, 2008
I would suggest using onControlTextChanging event instead of monitoring keystrokes - this way you also cover changes to the content from copy/paste and mouse operations.

var obj = new AW.UI.Input;

obj.onControlTextChanging = function(text){
    if (
text.match(/[^0-9]/)){    // check for non-digits
        
return 1// return an error code to cancel event
    
}
};

document.write(obj);
 
Alex (ActiveWidgets)
Thursday, January 31, 2008



This topic is archived.

Back to support forum

Forum search