Can anyone tell me why my strings doesn't trim. I have this code:
firstName = $('#form-create-user #first_name').val().trim().toLowerCase();
lastName = $('#form-create-user #last_name' ).val().trim().toLowerCase();
var initials = firstName.match(/\b\w/g) || [];
initials = ((initials.shift() || '') + (initials.pop() || '')).toLowerCase();
username = initials.concat(lastName);
$('#form-create-user #username').val(username);
I would like the username to be generated from firstname and lastname, expecting Juan De la to generate jdela.
But the output is for example:

.replace(/\s+/, "")should work (Regex that removes all spaces)