textInput.restrict -- a better way?

I have a text input interaction where I want to restrict the allowable characters AND play a sound when disallowed characters are entered.

Right now I have one messy IF condition to test for the allowable characters. I’ve been looking at ways to use the new RegExp with this, but it does not work when tested against textInput.restrict. I know there is an issue with type, but not sure how to deal with it.

Anyway, here’s what I have so far:


import fl.controls.TextInput;
var inputText:TextInput= new TextInput();
inputText.move(100,100);
inputText.restrict="0-9;.,";//numbers, comma and period allowed
addChild(inputText);
 
var allowedText:RegExp = /(\d|,|.)/;//numbers, comma and period allowed
 
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler, true);
 
function keyHandler(event:KeyboardEvent):void {
        //the trace below always return true, even if the key is a letter
       //trace(allowedText.test(String.fromCharCode(event.keyCode)));
 
 if ((event.keyCode > 47)&&(event.keyCode<58)||(event.keyCode==188)|| event.keyCode==190)) {
  trace((event.keyCode));

 } else {
  trace("disallowed key");
 }
}