angularjs - Formatting a 32 character random string in Javascript -


for reason have been unable find quick solution this. trying add dashes "randomly" generated 32 character string in javascript so:

from: aa681ebc64f642b1afa95ee2a5d87350
to: aa681ebc - 64f6 - 42b1 - afa9 - 5ee2a5d87350 (added spaces clarity)

i assume code along lines of

string.format(randomstring, {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}); 

but in javascript

current code (using angular-random-string.js):

var value = angular.uppercase(randomstring(32)); 

you can use this: (fiddle here)

var code = "aa681ebc64f642b1afa95ee2a5d87350";  var test = "aa681ebc-64f6-42b1-afa9-5ee2a5d87350"  var fcode = code.substring(0, 8) + "-" + code.substring(8, 12) + "-" + code.substring(12, 16) + "-" + code.substring(16, 20) + "-" + code.substring(20);    // test  console.log(test === fcode);


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -