magozi
New Coder
Hello,
I need help. I have this code:
The problem is that the first and last name is entered in the field. If I enter 4 words, for example "Juan Jose Perez Ruiz" it registers me as firstname "Juan Jose Perez" and as lastname "Ruiz.
And I would like the last 2 words to go to lastname and the first 2 to firstname.
Thanks in advance everyone.
I need help. I have this code:
Code:
splitFullname: function splitFullname(fullname, fullnameFormat) {
fullnameFormat = fullnameFormat || 'firstname_first';
var nameParts = fullname.split(NAME_SEPARATOR).map(function (part) {
return part.trim();
}).filter(function (part) {
return part !== '';
}),
firstname = '',
lastname = '';
if (fullnameFormat === 'firstname_first') {
if (nameParts.length > 1) {
lastname = nameParts.pop();
}
firstname = nameParts.join(NAME_SEPARATOR);
} else {
lastname = nameParts.shift();
firstname = nameParts.join(NAME_SEPARATOR);
}
return {
firstname: firstname,
lastname: lastname
};
},
The problem is that the first and last name is entered in the field. If I enter 4 words, for example "Juan Jose Perez Ruiz" it registers me as firstname "Juan Jose Perez" and as lastname "Ruiz.
And I would like the last 2 words to go to lastname and the first 2 to firstname.
Thanks in advance everyone.