# String.fromCharCode and keyCode

**URL:** <https://forum.kirupa.com/t/string-fromcharcode-and-keycode/226054>\
**Category:** flash\
**Created:** [May 17, 2007, 8:50pm UTC](https://forum.kirupa.com/t/string-fromcharcode-and-keycode/226054 "2007-05-17T20:50:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![annettegeek](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@annettegeek](https://forum.kirupa.com/u/annettegeek)\
**Post date:** [May 17, 2007, 8:50pm UTC](https://forum.kirupa.com/t/string-fromcharcode-and-keycode/226054/1 "2007-05-17T20:50:56Z")

</div>

I’d like to restrict users to entering only digits, a comma or period. What I have below works for the digits, but the trace returns fraction characters for the comma and periods.

Suggestions? Documentation for unicode?? Help!!!

(code requires textinput component in library)

```auto
 
import fl.controls.TextInput;
var allowedText:String = ",.1234567890" ;//"0-9;.,";
var inputText:TextInput= new TextInput();
inputText.move(100,200);
inputText.restrict= allowedText;
addChild(inputText);
 
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler, true);
 
function keyHandler(event:KeyboardEvent):void {
 trace("key="+String.fromCharCode(event.keyCode))
 
 if (allowedText.indexOf(String.fromCharCode(event.keyCode)) > -1 ){
  trace(("keyOK"));
 } else {
  trace("disallowed key");
 }
}

```
