Created
May 10, 2010 13:34
-
-
Save dkln/396041 to your computer and use it in GitHub Desktop.
Filter textinput in textfields in Actionscript 3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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