3.2.0

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
January 31,
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)
January 31,

This topic is archived.

See also:


Back to support forum