Return to Snippet

Revision: 33736
at October 12, 2010 22:35 by adrianparr


Initial Code
function removeNonNumericChars($str:String):String {
	var newStr:String = "";
	for (var i:int = 0; i<$str.length; i++) {
		var currentCharCode:Number = $str.charCodeAt(i);
		if ((currentCharCode >= 48) && (currentCharCode <= 57)) {
			newStr += $str.charAt(i);
		}
	}
	return newStr;
}

var myString:String = "#12abc345^67%89)([email protected]!foo";
trace("myString: "+myString);
myString = removeNonNumericChars(myString);
trace("myString: "+myString);

// OUTPUT
// myString: #12abc345^67%89)([email protected]!foo
// myString: 123456789

Initial URL


Initial Description


Initial Title
AS3 Remove Non-Numeric Characters from a String

Initial Tags


Initial Language
ActionScript 3