/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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)(-@!foo"; trace("myString: "+myString); myString = removeNonNumericChars(myString); trace("myString: "+myString); // OUTPUT // myString: #12abc345^67%89)(-@!foo // myString: 123456789