Converting keypress into a string of only numbers

Ok so after solving my last problem, i have a new one which i’ve tried to work on but have not yet succeeded :frowning:

What i want to do is to allow a user to input a time of when the alarm should sound. However, when i press like “2” or any number i get “22” instead of just “2”

Also, is there a way to stop people from entering letters along with this piece of code?

Here is how i attempted to do it:

var alarmTime:TextField = new TextField();
var textAlarmFormat:TextFormat = new TextFormat();
textAlarmFormat.align = TextFormatAlign.CENTER;
textAlarmFormat
addChild(alarmTime);
alarmTime.x = 100;
alarmTime.y = 6;
alarmTime.type = TextFieldType.INPUT;
alarmTime.defaultTextFormat = textAlarmFormat;

stage.addEventListener(KeyboardEvent.KEY_DOWN, checkTextInput);

function checkTextInput(e:KeyboardEvent){
    
    var character:String = String.fromCharCode(e.charCode);
    
    if (e.keyCode >=48 && e.keyCode <= 57)
    {
        alarmTime.text = character;
    }
    
}