Result is 123-456-789-0
1 2 3 4 5 |
var str = "1234567890"; str = str.replace(/(\S{3})/g,"$1-"); alert (str); |
Inserting twice at different positions
Result 123-456-7890
1 2 3 4 5 6 7 |
var str1 = "1234567890" var str2 = "-" str1 = str1.substr(0,3) + str2 + str1.substr(3,3) + str2 + str1.substr(6) alert(str1); |