JQuery Unique String Generator

JQuery Generate Unique String Based on Date Time and charachters

by Kanzari Haithem

HTML

<input type="text" id="uniqueIDResult" name="uniqueIDResult">
<button id="uniqueIDBTN" type="submit">Generate</button>

JavaScript

$( document ).ready(function() {

$(document).on("click", "#uniqueIDBTN", function() {
	$('#uniqueIDResult').val(generateUniqueID(2));
});
  
  var generateUniqueID = function(idlength){
  
    var charstoformid = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
    var ms = '' + +new Date;
    if (!idlength) {
      idlength = Math.floor(Math.random() * charstoformid.length);
    }
    var uniqid = '';
    for (var i = 0; i < idlength; i++) {
      uniqid += charstoformid[Math.floor(Math.random() * charstoformid.length)];
    }
    ms = ms.match(new RegExp('.{1,1}', 'g')).join(uniqid).split('').reverse().join('');
    return ms;
    
  };
  
    
});