Revision: 26711
Updated Code
at May 14, 2010 05:24 by adrianparr
Updated Code
function formattedMobileNum($numStr:String):String { var withNoSpaces:String = $numStr.split(" ").join(""); var part1:String = withNoSpaces.substr(0, 5); var part2:String = withNoSpaces.substr(5, withNoSpaces.length-1); var formatted = part1 + " " + part2; formatted = formatted.replace(/^\s+|\s+$/g, ""); return formatted; } var mobileNum:String = " 0 785 41 23 456 "; trace(formattedMobileNum(mobileNum)); // OUTPUT // 07854 123456
Revision: 26710
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 7, 2010 11:15 by adrianparr
Initial Code
function formattedMobileNum($numStr:String):String { var withNoSpaces:String = $numStr.split(" ").join(""); var part1:String = withNoSpaces.substr(0, 5); var part2:String = withNoSpaces.substr(5, withNoSpaces.length-1); var formatted = part1 + " " + part2; return formatted; } var mobileNum:String = " 0 785 41 23 456 "; trace(formattedMobileNum(mobileNum)); // OUTPUT // 07854 123456
Initial URL
Initial Description
This returns a string with a single space after the fifth character. Useful for displaying a UK mobile number which is easy to read.
Initial Title
AS3 Format a UK Mobile Number (XXXXX XXXXXX)
Initial Tags
number, format, mobile
Initial Language
ActionScript 3