Reputation: 45
I wrote one function it will take care of doing the capitalization of first name and last name. Now, if it has any special characters it was not making that word first letter as capital.
Example: When I give @TEST XYX it will convert this to @test Xyz but, I need @Test Xyz.
Below I'm attaching my code
camelCaseConvertion = function(str){
var lowerCase = String(str).toLowerCase();
return lowerCase.replace(/(^|\s)(\w)/g, function(text) {
return text.toUpperCase();
});
};
Upvotes: 0
Views: 64
Reputation: 1368
// you can put a check for non word characters
camelCaseConvertion = function(str){
var lowerCase = String(str).toLowerCase();
return lowerCase.replace(/(^|\s)[^\w]*(\w)/g, function(text) {
return text.toUpperCase();
});
};
Upvotes: 1