 <pre><code>&lt;script&gt; var key = "12k4353535352311"; var res = key.substring(0,4)+'-'+key.substring(4,12)+'-'+key.substring(12,16); //This contains 12k4-35353535-2311 &lt;/script&gt; </code></pre>