Like the following:
var unformatted="1234567891234"
var groups=/^(\d{3})(\d{5})(\d{3})(\d{2}$)/.exec(unformatted)
var formatted=groups[1]+"-"+groups[2]+"-"+groups[3]+"-"+groups[4]
console.log(formatted)
solved Number formatting using javascript [closed]