/ Published in: ActionScript 3

This returns a string with a single space after the fifth character.
Useful for displaying a UK mobile number which is easy to read.
Useful for displaying a UK mobile number which is easy to read.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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
Comments
