
Generate alphanumeric string that starts with not numeric character in Javascript
Alphanumeric is a description of data that is both numbers and letters.
Example:
“1a2b3c” is a short string of alphanumeric(numbers and letters) characters.
Alphanumeric is providing to explain the availability of text that can be entered or used(numbers and letters) in a field. Such as an alphanumeric password field.
const randomString = (len = 10) => {
const getRandomChar = (...params) => {
const symbols = params.join('');
return symbols[Math.floor(Math.random() * symbols.length)];
};
const alfas = 'abcdefghijklmnopqrstuvwxyz';
const nums = '0123456789';
const first = getRandomChar(alfas);
const rest = [...Array(len - 1)].map(() => getRandomChar(alfas, nums));
return [first, ...rest].join('');
};
console.log(randomString());
.as-console-wrapper { max-height: 100% !important; top: 0 }
Share: