To com(m)afiy a number say from 1234567 to 1,234,567.
function test() { n = "1234567"; alert(n.replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,"$1,")); }
Test the code
Credits to yossarian and h3h