How to generate a valid random mail using Jquery or Javascript
In this tutorial we will learn how to generate a random unique email address using Pure Javascript.
Use below code it will return a
function generateEmail() {
var allchars = 'abcdefghijklmnopqrstuvwxyz1234567890';
var emailLength = 15;
var string = '';
for(var i=0; i<emailLength; i++){
string += allchars[Math.floor(Math.random() * allchars.length)];
}
string = string + '@gmail.com';
return string;
}
var newEmail = generateEmail();
alert(newEmail);
Code Explain:
We have created "allchars" variable that contains all possible characters that our function will use, if you want to remove numbers from it or add capital letters , you can edit this string.
Then we have defined "emailLength" variable , You can change length of email according tou your requirement.
Then we are looping until the length and generating random string using Math functions.
Finally we are adding postfix email.
Now we can call this function anywhere in js.
Related Links
Nice Blog,
ReplyDeleteThe details that you mentioned in this blog regarding React js development.
I was searching for the best react js development company and found your blog.
Thanks for sharing such a great blog.
Synsoft Global