Xtreme-jQuery-Plugin
Self-written library as Addon for jQuery.
$.rand = function (length = 8, nosymbols = true, nonumbers = false) {
var symbols = "!#$%&()*+,-.:;<=>?@_";
var numbers = "0123456789";
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
if (nosymbols) {
characters += numbers;
} else {
characters += numbers + symbols;
}
if (nonumbers) {
characters = characters.replace(numbers, "");
}
var random_string = '';
for (var i = 0; i < length; i++) {
var char_index = 0;
if (i == 0) {
char_index = Math.floor(Math.random() * (characters.length - symbols.length));
} else if (i == length - 1) {
char_index = Math.floor(Math.random() * (characters.length - symbols.length - 1));
} else {
char_index = Math.floor(Math.random() * characters.length);
}
random_string += characters.charAt(char_index);
}
return random_string;
};
$.postJSON = function (url, data, callback) {
$.ajax({
url: url,
type: "POST",
data: data,
dataType: "json",
success: callback
});
};