Javascript examples for String:substring
Add hyphens to a string to format it as a 16-digit serial number
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w ww . ja v a 2 s . co m var randnum = "12345678910123456145"; var serial = randnum.substring(0,4) + "-" + randnum.substring(5,9) + "-" + randnum.substring(10,14) + "-" + randnum.substring(15,19); console.log(serial); } </script> </head> <body> </body> </html>