Skip to content Skip to sidebar Skip to footer

Javascript Creating A Username Using Inputs

I have a form in which the user inputs various information. The input chosen name allows the user to enter a username of choice but a HIDDEN INPUT needs to be integrated so that a

Solution 1:

I think the code found here is more suitable to generate a random string (you can put 20 characters instead of 10)

You can also just use md5() in the time or user email...

And you don't need to worry to create it in javascript, if this is random generated you can do that in php.

If you really need to do in javascript... there's CaffGeek answer in this post.. who could help you


Solution 2:

Add the below code before closing } of function validateForm() { and try

var username = '';
var date = new Date();
$.each(['surname', 'address', 'gname'], function() {
    username += $.trim($('input[name="' + this + '"]').val().replace(/\d+/g, '')).substring(0, 1);
});
username += date.getDate() + '' + date.getSeconds();
$('input[name="susername"]').val(username);

jsBin


Post a Comment for "Javascript Creating A Username Using Inputs"