Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dkln/396041 to your computer and use it in GitHub Desktop.
Save dkln/396041 to your computer and use it in GitHub Desktop.
Filter textinput in textfields in Actionscript 3.0
acceptedRegEx = "^[0-9]{0,3}[\.,]?[0-9]{0,2}$";
...
input.addEventListener(TextEvent.TEXT_INPUT, handleTextInput, false, 0, true);
...
private function handleTextInput(event:TextEvent):void {
var newText:String;
newText = input.text.substr(0, input.selectionBeginIndex) + event.text + input.text.substr(input.selectionEndIndex);
if(acceptedRegEx != "" && !(new RegExp(acceptedRegEx).test(newText)))
event.preventDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment